当价值增加时,textarea的高度增加,但当价值降低时,textarea的高度不会降低 [英] height of textarea increases when value increased but does not reduce when value is decreased
本文介绍了当价值增加时,textarea的高度增加,但当价值降低时,textarea的高度不会降低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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高度在减少它的值长度,它不会得到滚动条
When textarea get overflowed it get scrollbar and scrollheight which gets applied to its height but not working for decreasing textarea height as on decreasing its value length it doesnot get scrollbar
推荐答案
The minimum scrollHeight of a textarea is always going to be the height. To get an accurate scrollHeight, set the height to 1 first.
h.height(1).height(h[0].scrollHeight);
http://jsfiddle.net/aarongloege/t2vAr/
这篇关于当价值增加时,textarea的高度增加,但当价值降低时,textarea的高度不会降低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文