欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery文字填寫自動(dòng)高度的實(shí)現(xiàn)方法

 更新時(shí)間:2016年11月07日 10:09:04   投稿:jingxian  
下面小編就為大家?guī)硪黄猨query文字填寫自動(dòng)高度的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

下面開始寫一個(gè)jquery插件

(function($){
  $.fn.autoTextarea = function(options) {
    var defaults={
      maxHeight:null,//文本框是否自動(dòng)撐高,默認(rèn):null,不自動(dòng)撐高;如果自動(dòng)撐高必須輸入數(shù)值,該值作為文本框自動(dòng)撐高的最大高度
      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);

調(diào)用代碼示例:

<textarea name="textarea" id="textarea" cols="60" rows="4" class="chackTextarea-area"></textarea>
<script type="text/javascript">

  $(".chackTextarea-area").autoTextarea({
    maxHeight: 220,//文本框是否自動(dòng)撐高,默認(rèn):null,不自動(dòng)撐高;如果自動(dòng)撐高必須輸入數(shù)值,該值作為文本框自動(dòng)撐高的最大高度
  });

以上這篇jquery文字填寫自動(dòng)高度的實(shí)現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論