国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 司法| 绥阳县| 青岛市| 肇庆市| 阜城县| 阿合奇县| 四川省| 哈尔滨市| 合水县| 巧家县| 罗田县| 定陶县| 黑龙江省| 芦山县| 加查县| 易门县| 库尔勒市| 清徐县| 翼城县| 呼图壁县| 万宁市| 揭阳市| 胶州市| 辽宁省| 深水埗区| 民和| 沂源县| 天峨县| 阿图什市| 宣化县| 乐安县| 来凤县| 阿克| 洪雅县| 民勤县| 河北省| 黑河市| 东阳市| 新乡县| 衡阳县| 黄大仙区|