Javascript 高度不是一个函数
我试图构建一个小jQuery插件,但我得到一个错误,group.height()不是函数Javascript 高度不是一个函数,javascript,jquery,Javascript,Jquery,我试图构建一个小jQuery插件,但我得到一个错误,group.height()不是函数 (function( $ ) { $.fn.equalHeight = function(group) { group = $.extend(group); var tallest = 0; group.each(function () { var thisHeight = $(this).height();
(function( $ ) {
$.fn.equalHeight = function(group) {
group = $.extend(group);
var tallest = 0;
group.each(function () {
var thisHeight = $(this).height();
if (thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
// allow jQuery chaining
return this;
};
}( jQuery ));
用法示例如下所示:
<script>
// Usage example:
$( ".boxes section.box" ).equalHeight();
</script>
//用法示例:
$(“.box节.box”).equalHeight();
试试看
演示:使用此
?
在声明中,equalHeight接受一个参数,但没有传递任何内容。请注意,在自定义jQuery函数中,您不必传入组
,因为此
标识符已经指向您的组
因此,要么执行
group=this
,要么完全替换它$(this)引用的是each循环,而不是selectorUsegroup.each(function(){$(this).height(highty);})我想他是想设定高度,而不是担心——我的错。我现在明白了:)
(function ($) {
$.fn.equalHeight = function () {
var tallest = 0;
this.each(function () {
var thisHeight = $(this).height();
if (thisHeight > tallest) {
tallest = thisHeight;
}
});
// allow jQuery chaining
return this.height(tallest);
};
}(jQuery));