我查看了 jQuery 插件网站,它教我如何编写基本插件:
(function( $ ){
$.fn.maxHeight = function() {
var max = 0;
this.each(function() {
max = Math.max( max, $(this).height() );
});
return max;
};
})( jQuery );
然后,div 可以有maxHeight
方法,像这样:
var tallest = $('div').maxHeight(); // Returns the height of the tallest div
但我想只有textarea有maxHeight功能,但div没有。我怎样才能这样做呢?
你可以做...
this.filter('textarea')
如果你做一个each()
在返回的集合上,它只会迭代选定的textarea
元素。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)