gpt4 book ai didi

javascript - 高度不是函数

转载 作者:行者123 更新时间:2023-11-29 19:46:17 26 4
gpt4 key购买 nike

我正在尝试构建一个小的 jQuery 插件,但我收到一个错误,提示 group.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>

最佳答案

使用这个?在您的声明中,您的 equalHeight 接受一个参数,但您没有传递任何东西。请注意,在自定义 jQuery 函数中,您不必传入 group,因为 this 标识符已经引用了您的组。

所以,要么执行 group = this,要么完全替换它

关于javascript - 高度不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19360429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com