首页 > 其他 > 详细

textarea自适应高度

时间:2019-10-24 15:13:34      阅读:81      评论:0      收藏:0      [点我收藏+]
 1 (function ($) {
 2     $.fn.autoTextarea = function (options) {
 3         var defaults = {
 4             maxHeight: null,
 5             minHeight: $(this).height()
 6         };
 7         var opts = $.extend({}, defaults, options);
 8         return $(this).each(function () {
 9             $(this).bind("paste cut keydown keyup focus blur", function () {
10                 var height, style = this.style;
11                 this.style.height = opts.minHeight + px;
12                 if (this.scrollHeight > opts.minHeight) {
13                     if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
14                         height = opts.maxHeight;
15                         style.overflowY = scroll;
16                     } else {
17                         height = this.scrollHeight;
18                         style.overflowY = hidden;
19                     }
20                     style.height = height + px;
21                 }
22             });
23         });
24     };
25 })(jQuery);
26 $("textarea#txt_show").autoTextarea({
27     maxHeight: 2000,
28     minHeight: 80
29 }); 

 

textarea自适应高度

原文:https://www.cnblogs.com/xujunbao/p/11731779.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!