zoukankan      html  css  js  c++  java
  • Jquery实现textarea根据文本内容自适应高度

    本文给大家分享的是Jquery实现textarea根据文本内容自适应高度,这些在平时的项目中挺实用的,所以抽空封装了一个文本框根据输入内容自适应高度的插件,这里推荐给小伙伴们。

    autoTextarea.js

    (function($){
      $.fn.autoTextarea = function(options) {
        var defaults={
          maxHeight:null,
          minHeight:$(this).height()
        };
        var opts = $.extend({},defaults,options);
        return $(this).each(function() {
          $(this).bind("paste cut keydown keyup focus blur",function(){
            var height,style=this.style;
            this.style.height = opts.minHeight + 'px';
            if (this.scrollHeight > opts.minHeight) {
              if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
                height = opts.maxHeight;
                style.overflowY = 'scroll';
              } else {
                height = this.scrollHeight;
                style.overflowY = 'hidden';
              }
              style.height = height + 'px';
            }
          });
        });
      };
    })(jQuery);
    

      

     
    demo.js
    1 $(".doctable textarea").autoTextarea({
    2   maxHeight:400,
    3   minHeight:100
    4 });
  • 相关阅读:
    kafka副本
    kafka消息丢失
    kafka消费者
    RN8302b调试笔记
    MDK #pragma anon_unions
    [Python笔记]Strip
    [Python笔记]AnyAll
    [Python笔记]元组
    [Python笔记]列表
    嵌入式平台移植Python
  • 原文地址:https://www.cnblogs.com/laneyfu/p/5956576.html
Copyright © 2011-2022 走看看