天堂…中文在线最新版在线丨无码中文字幕va精品影院丨黄色三级在线视频丨日韩超碰丨亚洲a成人无码网站在线丨得得啪在线丨激情五月婷婷综合丨亚洲欧美国产国产综合一区丨色拍拍欧美视频在线看丨91欧美在线视频丨久久久久久国产精品免费播放丨2020年国产精品丨精品国产天线2019丨青草内射中出高潮丨成年美女黄网站色大免费视频丨欧美性猛烈丨色婷婷av一本二本三本浪潮丨天天视频色丨91性色丨国产精品午夜福利麻豆

????????? textarea高度隨內容自適應 ?????????

textarea高度隨內容自適應,不依賴任何第三方插件,若不需要自動高度,添加 data-allow="no-allow" 即可。

1534829885100604.jpg

textarea高度自適應代碼如下:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>textarea高度隨內容自適應,不依賴任何第三方插件</title>
  <style>
    * {
      margin: 0;
      padding: 0
    }
    .box {
      margin: 50px auto;
      border: 1px solid #ccc;
      width: 600px;
      min-height: 300px;
      padding: 10px;
    }
    textarea{padding: 5px;width: 30%}
  </style>
</head>
<body>
  <div>
    <h2>textarea高度隨內容自適應,不依賴任何第三方插件</h2>
    不需要自動高度,添加 data-allow="no-allow" 即可。
    <br><br><br>
    <textarea data-allow="no-allow"  placeholder="高度不變"></textarea>
    <textarea placeholder="高度自適應"></textarea>
    <textarea placeholder="高度自適應"></textarea>
  </div>
  <script>
    void function () {
      function DiyArea (el) {
        this.el = el || {}
        this.config = {
          el: document.querySelectorAll('textarea')
        }
        this.init()
      }
      DiyArea.prototype = {
        init: function () {
          this.bindEvent()
        },
        bindEvent: function () {
          if (!this.config.el) {
            return false
          }
          if (this.config.el[0].addEventListener) {
            for (var i = 0; i < this.config.el.length; i++) {
              if (this.config.el[i].getAttribute('data-allow') === 'no-allow') {
                continue
              }
              this.config.el[i].addEventListener('input', function (e) {
                console.log(this.style.height)
                this.style.height = 'auto'
                this.style.height = this.scrollHeight + 'px'
              })
            }
          }
        }
      }
      return new DiyArea('diy-area')
    }()
  </script>
</body>
</html>