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

  • 相关阅读:
    nginx下pagespeed使用详解
    letsencrypt证书-使用certbot申请wildcard证书
    letsencrypt证书-管理工具certbot
    tcpdump使用
    elasticsearch增删改查操作
    elasticsearch安装中文分词器
    dragstart drag dragend dragenter dragover dragleave drop
    js如何准确获取当前页面url网址信息
    /touch滑屏事件
    监听 手机back键和顶部的回退
  • 原文地址:https://www.cnblogs.com/dashi/p/4034730.html
Copyright © 2011-2022 走看看