textarea输入框回车加大高度

javascript

浏览数:203

2019-1-7

AD:资源代下载服务
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
function ResizeTextarea(a, row) {
    if (!a) {
        return
    }
    if (!row)
        row = 5;
    var b = a.value.split("\n");
    var c = is_ie ? 1 : 0;
    c += b.length;
    var d = a.cols;
    if (d <= 20) {
        d = 40
    }
    for (var e = 0; e < b.length; e++) {
        if (b[e].length >= d) {
            c += Math.ceil(b[e].length / d)
        }
    }
    c = Math.max(c, row);
    if (c != a.rows) {
        a.rows = c;
    }
}