700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > jquery实现文本框textarea自适应高度【javascript】

jquery实现文本框textarea自适应高度【javascript】

时间:2019-06-06 20:24:19

相关推荐

jquery实现文本框textarea自适应高度【javascript】

web前端|js教程

jquery文本框自适应高度,jquery,textarea自适应高度

web前端-js教程

浏览器中默认的文本框是不能根据内容的增多变高,只能固定高度有滚动条,体验不是很好,找了很多方法兼容都不行,总算找到个兼容良好的方法:

源码源资源站,ubuntu开机选系统,企查猫爬虫,php介绍,SEO专业院校lzw

$(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 _maxHeight ? _maxHeight : h; $(this).height(h).scrollTop(h); if (h >= _maxHeight) { $(this).css("overflow-y", "scroll"); } else { $(this).css("overflow-y", "hidden"); }}this.init(); }});

电视直播 apk源码,微加云ubuntu,群晖tomcat7密码,广州爬虫展蜘蛛,php大数据技术交流,永州seo外包lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。