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

  • 相关阅读:
    关闭caffe日志输出
    学习与工作中的认真和不认真
    深度学习_吴恩达_简单笔记
    JavaSE、JavaEE和JavaME的区别
    teamviewer
    提高深度学习检测网络准确率方法_未完待续
    提高深度学习分类模型准确率方法
    jQuery图片提示示例
    jQuery简单导航示例
    css盒子模型
  • 原文地址:https://www.cnblogs.com/dashi/p/4034730.html
Copyright © 2011-2022 走看看