您好,欢迎访问一九零五行业门户网

设置多行文本框[textarea]自动生成高度

这次给大家带来设置多行文本框[textarea]自动生成高度,设置多行文本框[textarea]自动生成高度的注意事项有哪些,下面就是实战案例,一起来看一下。
实现功能:
1/当textarea换行时自动增加一行高度
2/当textarea删除一行时 自动减少一行的高度 依赖:jquery.xxx.js 工作中需要使用类似功能但是觉得使用插件需要导入其他文件很不方便所以就写了一个
textarea jquery插件
<p class="form-group"> <label class="col-sm-3 control-label no- padding-right " for="form-field-5"> 内容</label> <p class="col-sm-9"> <textarea class="col-sm-8" id="form-field-5" placeholder="请输入内容..."></textarea> </p> </p>
jquery.extend({ textareaautosize_dc: function() { $("textarea").on("keyup", function(e) { var current entercount = $(this).val().split("\n").length; var lineheight = number($(this).css(" line-height ").replace("px", "")); var entercount = $(this).attr("entercount"); if (currententercount < entercount && entercount != undefined) { //每行减掉固定行高 $(this).height($(this).height() - lineheight); } else if (currententercount > entercount) { //每行加入固定行高 $(this).height($(this).height() + lineheight); $(this).attr("entercount", currententercount); } //记录当前行高 $(this).attr("entercount", currententercount); }); } }); //调用自动高度 $.textareaautosize_dc();
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery+mobile自定义按钮图标步骤详解
jquery+mobile自定义按钮图标步骤详解
以上就是设置多行文本框[textarea]自动生成高度的详细内容。
其它类似信息

推荐信息