<body>
<script type="text/javascript">$(function(){
$("textarea").live("keyup keydown",function(){var h=$(this);
h.height(h[0].scrollHeight);
});});
</script>
<textarea style="resize:none;width:760px;height:60px; overflow:hidden;" ></textarea>
</body>
当 textarea 溢出时,它会得到滚动条和 scrollheight,这会应用于它的高度,但不能用于降低 textarea 高度,因为在减小它的值长度时它不会得到滚动条
最佳答案
textarea 的最小 scrollHeight 始终是高度。要获得准确的 scrollHeight,请先将高度设置为 1。
h.height(1).height(h[0].scrollHeight);
关于javascript - textarea 的高度在值增加时增加,但在值减小时不减小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10722058/