• textarea高度自适应


    var $textarea = document.getElementById('textarea0');
               console.log($textarea)
              var lastLength = 0;
              var lastHeight = 0;
              $textarea.addEventListener('input', function() {
                  var currentLength = $textarea.value.length;
                  // 判断字数如果比之前少了,说明内容正在减少,需要清除高度样式,重新获取
                  if (currentLength < lastLength) {
                      $textarea.style.height = '';
                  }
                  var currentHeight = $textarea.scrollHeight;
                  // 如果内容高度发生了变化,再去设置高度值
                  if (lastHeight !== currentHeight || !$textarea.style.height) {
                      $textarea.style.height = currentHeight + 2 + 'px';
                  }
                  lastLength = currentLength;
                  lastHeight = currentHeight;
              });
    

      

  • 相关阅读:
    redis修改密码
    redis配置
    django中日志配置
    django中缓存配置
    navicat批量导入数据
    django添加REST_FRAMEWORK 接口浏览
    django验证码配置与使用
    LUA_OBJECT
    LUA comment
    lua-redis
  • 原文地址:https://www.cnblogs.com/love314159/p/14344083.html
Copyright © 2020-2023  润新知