国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery實現文本框textarea自適應高度

2019-11-20 10:25:38
字體:
來源:轉載
供稿:網友

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

<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() {        //最小高度和最大高度默認        $("#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>

以上就是本文的全部內容,希望對大家學習jquery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 渝中区| 澄城县| 丰城市| 泸定县| 耿马| 明水县| 东光县| 藁城市| 巢湖市| 额敏县| 衡阳市| 冀州市| 滨州市| 晋城| 鄱阳县| 隆子县| 河津市| 平遥县| 迭部县| 温泉县| 东平县| 永定县| 明水县| 黔西县| 黄冈市| 永修县| 吴桥县| 喜德县| 通山县| 岗巴县| 额济纳旗| 福泉市| 横山县| 临安市| 赤水市| 天柱县| 天长市| 新民市| 互助| 开封县| 无极县|