zoukankan      html  css  js  c++  java
  • textarea自增高(无滚动条)纯js实现

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html>
    <body>
      <textarea onkeyup="MaxMe(this)" style="overflow: hidden"></textarea>
      <script type="text/javascript">
        function MaxMe(o) {     
          if (window.navigator.userAgent.indexOf("Firefox") > -1) {
            o.style.height = o.scrollTop + o.scrollHeight + "px";
          }
          else {
            if (o.scrollTop > 0) o.style.height = o.scrollTop + o.scrollHeight + "px";
          }
        }
      </script>
      <div id="debug"></div>
    </body>
    </html>

    或者

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html>
    <head>
      <title>Javascript 实现 Textarea 自动伸缩,兼容IE6、IE7、IE8、IE9、Firefox、Safari、Chome、Opera</title>
    </head>
    <body>
    <table>
      <tr valign="top">
      <td><textarea id="textarea" style="overflow: hidden"></textarea></td>
      <td><textarea onpropertychange="MaxMe(this)" oninput="MaxMe(this)" ontextinput="MaxMe(this)" style="overflow: hidden"></textarea></td>
      </tr>
    </table>
    <script type="text/javascript">
      function MaxMe(o) {
        if (window.navigator.userAgent.indexOf("Firefox") > -1) {
          o.style.height = o.scrollTop + o.scrollHeight + "px";
        }
        else {
          if (o.scrollTop > 0) o.style.height = o.scrollTop + o.scrollHeight + "px";
        }
      }
      
      function Init() {
        var textarea = document.getElementById("textarea");
        if (textarea.addEventListener) {    // 非Internet Explorer和Internet Explorer9之后的版本
          textarea.addEventListener("input", OnTextInput, false);
          // Google Chrome 和 Safari
          textarea.addEventListener("textinput", OnTextInput, false);
        }
      
        if (textarea.attachEvent) { // Internet Explorer 和 Opera
          textarea.attachEvent("onpropertychange", OnTextInput);
        }
      }
      
      function OnTextInput(evt) {
        o = window.event ? window.event.srcElement : evt.target;
        if (window.navigator.userAgent.indexOf("Firefox") > -1) {
          o.style.height = o.scrollTop + o.scrollHeight + "px";
        }
        else {
          if (o.scrollTop > 0) o.style.height = o.scrollTop + o.scrollHeight + "px";
        }
      }
      window.onload = Init;
    </script>
    </body>
    </html>
  • 相关阅读:
    可视化工具之 IGV 使用方法
    SAM格式 及 比对工具之 samtools 使用方法
    比对工具之 BWA 使用方法
    项目一:使用二代测序数据进行基因组组装(局部组装)
    Linux 打包和压缩 方法详解
    Oracle 11G R2 RAC中的scan ip 的用途和基本原理【转】
    ORACLE表空间查询和管理【转】
    MySQL分布式集群之MyCAT(三)rule的分析【转】
    MySQL分布式集群之MyCAT(二)【转】
    linux快速复制大量小文件方法 nc+tar【转】
  • 原文地址:https://www.cnblogs.com/iwenwen/p/3128059.html
Copyright © 2011-2022 走看看