【jQuery插件】autoTextarea-文本框根据输入内容自适应高度【蕃薯耀分享】
【jQuery插件】autoTextarea-文本框根据输入内容自适应高度
(function($){
$.fn.autoTextarea = function(options) {
var defaults={
maxHeight:null,//文本框是否自动撑高,默认:null,不自动撑高;如果自动撑高必须输入数值,该值作为文本框自动撑高的最大高度
minHeight:$(this).height() //默认最小高度,也就是文本框最初的高度,当内容高度小于这个高度的时候,文本以这个高度显示
};
var opts = $.extend({},defaults,options);
return $(this).each(function() {
$(this).bind("paste cut keydown keyup focus blur",function(){
var height,style=this.style;
this.style.height = opts.minHeight + 'px';
if (this.scrollHeight > opts.minHeight) {
if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
height = opts.maxHeight;
style.overflowY = 'scroll';
} else {
height = this.scrollHeight;
style.overflowY = 'hidden';
}
style.height = height + 'px';
}
});
});
};
})(jQuery);调用:
$(".chackTextarea-area").autoTextarea({maxHeight:220});转自:http://www.css88.com/archives/3948
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2013年1月26日 10:27:18 星期六
相关推荐
王练 2020-06-12
81463166 2020-05-16
Reiki 2020-05-04
82550495 2020-05-01
zcl 2020-03-04
donghongbz 2020-01-17
tangfenjuan 2019-12-02
heshanking 2019-10-29
Passerby 2019-10-28
89463661 2019-11-05
Clarence 2011-11-18
chang00 2015-06-17
xuewenke 2012-05-19
87281248 2018-03-13
zZoOoOJaVa 2018-02-19
mianhuantang 2009-12-11
srchange 2019-08-19
echoright晓戈 2011-11-21
yuqiuyao 2018-11-23