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";
        }

  • 相关阅读:
    【数据库】mysql 服务不能安装 与闪退
    【vue】遍历循环添加a标签的属性值 与获取某个属性值
    写在大一
    一些关于新材料研究的想法
    我的大学求学之路
    河南洛阳中铝洛铜实习
    html-制作导航菜单
    全局CSS的配置
    手扭到了
    第一次用,大家照顾哈
  • 原文地址:https://www.cnblogs.com/dashi/p/4034730.html
Copyright © 2011-2022 走看看