Textarea 高度自适应 根据内容自适应高度


   

   

   
   

   

   


  function init() {
        // 设置textarea自适应高度
        var handler = function () {
            setTareaAutoHeight('textarea');
        };

        // 添加监听
        if (window.addEventListener) {//FF
            window.addEventListener('DOMContentLoaded', handler, false);
            window.addEventListener('load', handler, false);
        } else if (window.attachEvent)//IE
            window.attachEvent('onload', handler);
        else
            window.onload = handler;
    } // end init

    init();

    function setTareaAutoHeight(id) {
        document.getElementById(id).style.height = document.getElementById(id).scrollHeight + "px";
    }

你可能感兴趣的:(css,js,function,border,server,div)