×

用jQuery让textarea自动增长

作者:前端菜鸟2017.07.26来源:Web前端之家浏览:10323评论:0
关键词:JQueryJS

本文实例讲述了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>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1483372800855.html

网友评论文明上网理性发言 已有0人参与

发表评论: