English 中文(简体)
当值增加时文本区域高度增加,但当值减少时不会减少
原标题:height of textarea increases when value increased but does not reduce when value is decreased
<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>

当文本区域溢出时, 它会得到滚动条和滚动列, 滚动条和滚动线可以应用到它的高度上, 但不工作于降低文本区域高度, 因为它在降低其值长度时不会得到滚动条

最佳回答

文本区域最小的滚动58总是高度。 要获得准确的滚动58, 请先将高度设定为 1 。

h.height(1).height(h[0].scrollHeight);

http://jsfidle.net/aarongloge/t2vAr/" rel="nreferrer">http://jsfidle.net/aarongloge/t2vAr/

问题回答

上述代码的纯 JavaScript 版本

textarea.style.height =  0 ;
textarea.style.height = textarea.scrollHeight +  px ;

If you do not want to code it by yourself, you can also use this script: https://github.com/brandonaaron/jquery-expandable It already contains a nice slide-effect ;-)





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签