html:
<textarea name="textarea" id="textarea_id" style='overflow-y: hidden;height:30px' onpropertychange="this.style.height = this.scrollHeight + 'px';" oninput="this.style.height = this.scrollHeight + 'px';"></textarea>
js:
<script>
//拿到TextArea的DOM
var textarea=document.getElementById('textarea_id');
//设置高度
textarea.style.height = textarea.scrollHeight + 'px';
</script>
本文介绍了一种使用HTML和JS实现的自适应文本区域高度的方法,通过监听textarea的高度变化并实时调整,确保输入框始终能完美适配内容长度。
5万+

被折叠的 条评论
为什么被折叠?



