jQuery:“A 未定义”抛出错误并且 JSLint 提示“jQuery(...) 调用不正确”这里出了什么问题?

发布于 2024-10-26 08:38:29 字数 5679 浏览 1 评论 0原文

我通常不会发布此类内容,但我完全没有想法,经过几个小时的尝试修复此问题后,我根本不知道在哪里查找错误或此错误的含义。

中断的页面可在此处找到: http://staging.mathewhawley.com/

我已经构建了一些 < code>columnizer jQuery 插件似乎会导致此错误,但对我来说,我在插件中编写的所有内容似乎都是完全有效的。

打开 Firebug consoleJSLint 将记录以下内容:

jQuery(...) called incorrectly
jquery.lint.js (line 96)
More info:
jquery.lint.js (line 111)
jQuery(...) called incorrectly
jquery.lint.js (line 96)
More info:
jquery.lint.js (line 111)
a is undefined
[Break On This Error] (function(a,b){function cg(a){return d...a:a+"px")}}),a.jQuery=a.$=d})(window);
jquery.min.js (line 16)

单击“更多信息”链接,我得到以下信息:

Location:
jquery.lint.js (line 111)

You passed: ["#projects", undefined, jQuery(Document index.php)]

Available signatures include:
jQuery(selector, [context])
jQuery(element)
jQuery(elementArray)
jQuery(jQuery object)
jQuery()
jQuery(html, [ownerDocument])
jQuery(html, props)
jQuery(callback)

我正在通过以下方式使用最新的 jQuery 版本 : Google CDN ()。

另外,对于那些不喜欢查看外部页面的人,这里是我的专栏脚本,它似乎破坏了一些东西:

script.js // this file invokes all javascript.
jQuery(document).ready(function($) {

    // helper
    function scrollable() {
        if ( $.browser.webkit ) { 
            return $('body'); 
        } else {
            return $('html');
        }
    }

    // =========================
    // = Stuff on the homepage =
    // =========================
    if ( $('#projects').length ) { 

        $('#projects').children().hide();

        // Create column layout
        $(window).load(function() {

            $('#projects').columnize();

            function _reveal( el ) {
                if ( el !== undefined ) { 
                    el.fadeIn( 100 , function() { _reveal($(this).next()); });
                }
            }
            _reveal( $('#projects').children().first() );
        });

    }

    // =============================
    // = Stuff on the project page =
    // =============================
    // Add sticky project info
    if ( $('#project').length ) { 

        $('article','#project').sticky();
        // Back to Top link
        $('nav a[href=#tothetop]').click(function(e) {
            e.preventDefault();
            scrollable().animate({'scrollTop':0}, 400);
        });

    }

});

 jquery.columnizer.js // the columnizer helper script
(function($){
    $.fn.extend({ 
        columnize: function(options) {

            var defaults = {
                columns : 3,
                gutter  : 20
            },
                options = $.extend(defaults, options),
                o = options,
                internal = {},
                _i = internal;

            _i.container        = $(this); // container
            _i.containerHeight  = 0; // container
            _i.items            = _i.container.children(); // elements inside container
            _i.w                = _i.items.first().width();
            _i.columns          = {};
            _i.colHeight        = {};

            // Setup the container and its children's position
            _i.container.css({
                'position': 'relative'
            }).children().css({
                'position': 'absolute'
            });

            // cycle through all items and place them into arrays by column
            _i.items.each(function(i) {

                var itemPlace = i%o.columns; // get the column
                var col = itemPlace + 1; // start index at 1

                if ( _i.columns[col] === undefined ) {
                    _i.columns[col] = [$(this)]; // if the column doesn't already exist create it
                } else {
                    _i.columns[col].push($(this)); // otherwise add the current element to the correct column
                }

                var left = itemPlace * (_i.w + o.gutter); // calculate the left offset for the columns

                $(this).css({
                    'left': left + 'px', // apply the offset
                    'margin-left': 0     // and make sure no margin-left is on the container
                });

            });

            // Cycle through the existing columns
            for (var x=1; x <= o.columns; x++) {

                if ( _i.colHeight[x] === undefined ) { // create variables for storing the top offset to be applied to elements of this column
                     _i.colHeight[x] = 0; // start at creating it and setting it to 0
                }

                $.each(_i.columns[x], function(z, el) { // within each column cycle through its items

                    $el = $(el);
                    $el.css('top', _i.colHeight[x]+'px'); // set the top offset
                    _i.colHeight[x] += $el.outerHeight(true); // then add this elements height to the same variable

                });

            };
            // go through the columns
            $.each(_i.colHeight, function(key, val) {
                if ( _i.containerHeight < val ) { 
                     _i.containerHeight = val; // if this column's height is greater than the currently stored height, replace the height with this one
                }
            });
            _i.container.css({
                'height': _i.containerHeight+'px', // set the outer container to the tallest column's height
                'overflow':'hidden'
            });
            // done.
        }
    });
})(jQuery);

任何帮助将非常感激。

感谢您阅读本文,

詹尼斯

I normally don't post this kind of thing but I am completely out of ideas and after hours of trying to fix this thing I simply don't know where to look for the error or what this error even means.

The page that breaks is available here: http://staging.mathewhawley.com/

I have build a little columnizer jQuery plugin which seems to cause this error but to me it looks like everything I've written in the plugin is perfectly valid.

Turning on the Firebug console and JSLint the following is being logged:

jQuery(...) called incorrectly
jquery.lint.js (line 96)
More info:
jquery.lint.js (line 111)
jQuery(...) called incorrectly
jquery.lint.js (line 96)
More info:
jquery.lint.js (line 111)
a is undefined
[Break On This Error] (function(a,b){function cg(a){return d...a:a+"px")}}),a.jQuery=a.$=d})(window);
jquery.min.js (line 16)

Clicking on the "more info" link I get the following:

Location:
jquery.lint.js (line 111)

You passed: ["#projects", undefined, jQuery(Document index.php)]

Available signatures include:
jQuery(selector, [context])
jQuery(element)
jQuery(elementArray)
jQuery(jQuery object)
jQuery()
jQuery(html, [ownerDocument])
jQuery(html, props)
jQuery(callback)

I'm using the latest jQuery version via the Google CDN (<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>).

Also just for those that don't like looking at an external page, here is my columnizer script that seems to break things:

script.js // this file invokes all javascript.
jQuery(document).ready(function($) {

    // helper
    function scrollable() {
        if ( $.browser.webkit ) { 
            return $('body'); 
        } else {
            return $('html');
        }
    }

    // =========================
    // = Stuff on the homepage =
    // =========================
    if ( $('#projects').length ) { 

        $('#projects').children().hide();

        // Create column layout
        $(window).load(function() {

            $('#projects').columnize();

            function _reveal( el ) {
                if ( el !== undefined ) { 
                    el.fadeIn( 100 , function() { _reveal($(this).next()); });
                }
            }
            _reveal( $('#projects').children().first() );
        });

    }

    // =============================
    // = Stuff on the project page =
    // =============================
    // Add sticky project info
    if ( $('#project').length ) { 

        $('article','#project').sticky();
        // Back to Top link
        $('nav a[href=#tothetop]').click(function(e) {
            e.preventDefault();
            scrollable().animate({'scrollTop':0}, 400);
        });

    }

});

.

 jquery.columnizer.js // the columnizer helper script
(function($){
    $.fn.extend({ 
        columnize: function(options) {

            var defaults = {
                columns : 3,
                gutter  : 20
            },
                options = $.extend(defaults, options),
                o = options,
                internal = {},
                _i = internal;

            _i.container        = $(this); // container
            _i.containerHeight  = 0; // container
            _i.items            = _i.container.children(); // elements inside container
            _i.w                = _i.items.first().width();
            _i.columns          = {};
            _i.colHeight        = {};

            // Setup the container and its children's position
            _i.container.css({
                'position': 'relative'
            }).children().css({
                'position': 'absolute'
            });

            // cycle through all items and place them into arrays by column
            _i.items.each(function(i) {

                var itemPlace = i%o.columns; // get the column
                var col = itemPlace + 1; // start index at 1

                if ( _i.columns[col] === undefined ) {
                    _i.columns[col] = [$(this)]; // if the column doesn't already exist create it
                } else {
                    _i.columns[col].push($(this)); // otherwise add the current element to the correct column
                }

                var left = itemPlace * (_i.w + o.gutter); // calculate the left offset for the columns

                $(this).css({
                    'left': left + 'px', // apply the offset
                    'margin-left': 0     // and make sure no margin-left is on the container
                });

            });

            // Cycle through the existing columns
            for (var x=1; x <= o.columns; x++) {

                if ( _i.colHeight[x] === undefined ) { // create variables for storing the top offset to be applied to elements of this column
                     _i.colHeight[x] = 0; // start at creating it and setting it to 0
                }

                $.each(_i.columns[x], function(z, el) { // within each column cycle through its items

                    $el = $(el);
                    $el.css('top', _i.colHeight[x]+'px'); // set the top offset
                    _i.colHeight[x] += $el.outerHeight(true); // then add this elements height to the same variable

                });

            };
            // go through the columns
            $.each(_i.colHeight, function(key, val) {
                if ( _i.containerHeight < val ) { 
                     _i.containerHeight = val; // if this column's height is greater than the currently stored height, replace the height with this one
                }
            });
            _i.container.css({
                'height': _i.containerHeight+'px', // set the outer container to the tallest column's height
                'overflow':'hidden'
            });
            // done.
        }
    });
})(jQuery);

Any help would be very much appreciated.

Thanks for reading this far,

Jannis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淤浪 2024-11-02 08:38:29

您的列生成器默认为三列(columns 在其 defaults 对象中为 3。)当您在“#projects”上调用它时,只有两篇文章。您的插件(第 50 行,jquery.columnize.js)在只有两列的对象上从 x = 1 到 3 循环。然后将一个 null 对象传递给 jQuery 的each() 函数,这就是导致错误的原因。

Your columnizer defaults to three columns (columns is 3 in its defaults object.) When you call it on "#projects", there are only two articles. Your plugin (on line 50, jquery.columnize.js) is looping from x = 1 to 3 on an object with only two columns. That's then passing a null object to jQuery's each() function, which is what is causing the error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文