最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery實現(xiàn)文本框textarea自適應(yīng)高度

 更新時間:2016年03月09日 10:07:01   作者:彼岸花在開  
這篇文章主要介紹了jquery實現(xiàn)文本框textarea自適應(yīng)高度的相關(guān)資料,需要的朋友可以參考下

瀏覽器中默認(rèn)的文本框是不能根據(jù)內(nèi)容的增多變高,只能固定高度有滾動條,體驗不是很好,找了很多方法兼容都不行,總算找到個兼容良好的方法:

<body>
    <textarea id="textarea3" style="overflow-y:hidden; height:20px;resize: none">
     
    </textarea>
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
      $(function() {
        //最小高度和最大高度默認(rèn)
        $("#textarea1").textareaAutoHeight();
        //最大高度為100px
        $("#textarea2").textareaAutoHeight({maxHeight: 100});
        //最小高度為50px,最大高度為200px
        $("#textarea3").textareaAutoHeight({minHeight: 50, maxHeight: 200});
      })
 
 
      $.fn.extend({
        textareaAutoHeight: function(options) {
          this._options = {
            minHeight: 0,
            maxHeight: 1000
          }
 
          this.init = function() {
            for (var p in options) {
              this._options[p] = options[p];
            }
            if (this._options.minHeight == 0) {
              this._options.minHeight = parseFloat($(this).height());
            }
            for (var p in this._options) {
              if ($(this).attr(p) == null) {
                $(this).attr(p, this._options[p]);
              }
            }
            $(this).keyup(this.resetHeight).change(this.resetHeight)
                .focus(this.resetHeight);
          }
          this.resetHeight = function() {
            var _minHeight = parseFloat($(this).attr("minHeight"));
            var _maxHeight = parseFloat($(this).attr("maxHeight"));
 
            if (!$.browser.msie) {
              $(this).height(0);
            }
            var h = parseFloat(this.scrollHeight);
            h = h < _minHeight ? _minHeight :h > _maxHeight ? _maxHeight : h;
            $(this).height(h).scrollTop(h);
            if (h >= _maxHeight) {
              $(this).css("overflow-y", "scroll");
            }
            else {
              $(this).css("overflow-y", "hidden");
            }
          }
          this.init();
        }
      });
    </script>
  </body>

以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)jquery程序設(shè)計有所幫助。

相關(guān)文章

最新評論

南澳县| 永兴县| 旺苍县| 昆山市| 威海市| 苏尼特左旗| 资溪县| 樟树市| 清流县| 德化县| 丹东市| 碌曲县| 樟树市| 裕民县| 东平县| 金坛市| 麦盖提县| 东安县| 固镇县| 林西县| 田阳县| 芷江| 仙居县| 高台县| 黄浦区| 竹溪县| 屏边| 莫力| 乌拉特前旗| 武鸣县| 陈巴尔虎旗| 长寿区| 河北省| 临潭县| 疏附县| 油尖旺区| 顺昌县| 普陀区| 双鸭山市| 甘孜县| 沐川县|