zoukankan      html  css  js  c++  java
  • Textarea 高度自适应 根据内容自适应高度

    <body>
        <form id="form1" runat="server">
        <div>
        <textarea id='textarea' name="textarea" onpropertychange='setTareaAutoHeight("textarea")' oninput='setTareaAutoHeight("textarea")' style="100%; overflow-y:hidden; border:0; font-size:12px"><asp:Literal ID="litCont" runat="server"></asp:Literal></textarea>
        <!--
    IE支持 onPropertyChange 火狐支持oninput

    Firefox有个oninput事件效果和onPropertyChange一样,所以同时加上oninput和onPropertyChange问题就解决
    -->

        </div>
        </form>
    </body>
      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";
        }

  • 相关阅读:
    TX2--安装跑一python3.5
    luogu P4762 [CERC2014]Virus synthesis (回文自动机)
    牛客 128A 礼物 (组合计数)
    后缀自动机学习
    Codeforces Round #309 (Div. 1)
    Vanya and Scales CodeForces
    5-45 航空公司VIP客户查询 (25分) HASH
    转载 字符串hash
    5-15 QQ帐户的申请与登陆 (25分) HASH
    5-14 电话聊天狂人 (25分) HASH
  • 原文地址:https://www.cnblogs.com/dashi/p/4034730.html
Copyright © 2011-2022 走看看