Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 高度不是一个函数_Javascript_Jquery - Fatal编程技术网

Javascript 高度不是一个函数

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();

我试图构建一个小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>

//用法示例:
$(“.box节.box”).equalHeight();
试试看

演示:

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


因此,要么执行
group=this
,要么完全替换它

$(this)引用的是each循环,而不是selectorUse
group.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));