美文网首页网页前端后台技巧(CSS+HTML)ionic2.0+实战
小技巧——html的textarea标记跟随文本内容自适应高度

小技巧——html的textarea标记跟随文本内容自适应高度

作者: 全栈弄潮儿 | 来源:发表于2018-07-13 11:38 被阅读18次

textarea高度自适应

html代码:
<textarea id="textarea" style='overflow-y: hidden;height:20px' onpropertychange="this.style.height = this.scrollHeight + 'px';" oninput="this.style.height = this.scrollHeight + 'px';" onclink="send();">
</textarea>

js:
<script>
function send() {
//拿到TextArea的DOM
var textarea=document.getElementById('textarea');
//设置高度
textarea.style.height = 20 + 'px';
}
</script>

效果:


testarea.gif

相关文章

网友评论

    本文标题:小技巧——html的textarea标记跟随文本内容自适应高度

    本文链接:https://www.haomeiwen.com/subject/gnkjpftx.html