Home >Web Front-end >JS Tutorial >jQuery's method to realize automatic growth of textarea width and height_jquery
The example in this article describes how jQuery realizes the automatic growth of textarea width and height. Share it with everyone for your reference, the details are as follows:
<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>
I hope this article will be helpful to everyone in jQuery programming.