本文實例講述了jQuery實現textarea自動增長寬高的方法。分享給大家供大家參考,具體如下:
<script type="text/javascript">$(function(){$("#iptcont").bind("keydown",function(e){var key = e.which,that = this,h = 20;if (key == 13) {var brs = $(this).val().split("/n").length+1;$(this).attr("rows",brs).height(h*brs);}else if(key == 8){window.setTimeout(function(){var brs = $(that).val().split("/n").length;$(that).attr("rows",brs).height(h*brs);},100);}});});</script><body><textarea id="iptcont" rows="1" style="border:none;height:20px;border-bottom:1px solid blue;width:200px;resize:none;font-size:18px;line-height:20px;overflow:hidden;"></textarea></body>
希望本文所述對大家jQuery程序設計有所幫助。