日期:2014-05-16  浏览次数:20386 次

textarea自动伸缩问题
本帖最后由 chate 于 2013-11-27 16:44:03 编辑
如下代码在IE浏览器里伸缩自如,但是到了chrome或FF里,连续回车换行再删除或整段删除文字就不能自动缩短到应有位置了:
<textarea name="textarea" id="textarea" 
style='overflow-y: hidden;height:20px' 
onpropertychange="this.style.height = this.scrollHeight + 'px';" 
oninput="this.style.height = this.scrollHeight + 'px';">
</textarea>

有办法解决吗?

------解决方案--------------------
<textarea name="textarea" id="textarea" style='height:20px' onpropertychange="this.style.height = this.scrollHeight + 'px';"  oninput="this.style.height='auto';this.style.height = this.scrollHeight + 'px'">