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

jquery 插件实现多行文本框[textarea]自动高度_jquery

实现功能:
1/当textarea换行时自动增加一行高度
2/当textarea删除一行时 自动减少一行的高度 依赖:jquery.xxx.js 工作中需要使用类似功能但是觉得使用插件需要导入其他文件很不方便所以就写了一个
textarea jquery插件
复制代码 代码如下:
内容
复制代码 代码如下:
jquery.extend({
    textareaautosize_dc: function() {
        $(textarea).on(keyup, function(e) {
            var currententercount = $(this).val().split(\n).length;
            var lineheight = number($(this).css(line-height).replace(px, ));
            var entercount = $(this).attr(entercount);
            if (currententercount                 //每行减掉固定行高
                $(this).height($(this).height() - lineheight);
            } else if (currententercount > entercount) {
                //每行加入固定行高
                $(this).height($(this).height() + lineheight);
                $(this).attr(entercount, currententercount);
            }
            //记录当前行高
            $(this).attr(entercount, currententercount);
        });
    }
});
//调用自动高度
$.textareaautosize_dc();
以上就是本文的全部内容了,希望大家能够喜欢。
其它类似信息

推荐信息