jQuery:;A是未定义的“;抛出错误,JSLint说;jQuery(…)调用不正确;这里怎么了?
我通常不会发布这类东西,但我完全没有想法,在尝试修复这类东西几个小时后,我根本不知道该在哪里查找错误,甚至不知道这个错误意味着什么 此处提供了断开的页面: 我构建了一个小小的jQuery:;A是未定义的“;抛出错误,JSLint说;jQuery(…)调用不正确;这里怎么了?,jquery,warnings,undefined,jslint,Jquery,Warnings,Undefined,Jslint,我通常不会发布这类东西,但我完全没有想法,在尝试修复这类东西几个小时后,我根本不知道该在哪里查找错误,甚至不知道这个错误意味着什么 此处提供了断开的页面: 我构建了一个小小的专栏作家jQuery插件,它似乎导致了这个错误,但对我来说,我在插件中编写的所有内容都是完全有效的 打开Firebug控制台和JSLint将记录以下内容: jQuery(...) called incorrectly jquery.lint.js (line 96) More info: jquery.lint.js (li
专栏作家jQuery插件,它似乎导致了这个错误,但对我来说,我在插件中编写的所有内容都是完全有效的
打开Firebug控制台
和JSLint
将记录以下内容:
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)
我正在通过Google CDN(
)使用最新的jQuery版本
同样,对于那些不喜欢查看外部页面的人,这里是我的专栏作家脚本,它似乎打破了一些东西:
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//columnizer助手脚本
(函数($){
$.fn.extend({
列化:函数(选项){
var默认值={
栏目:3,
排水沟:20
},
选项=$.extend(默认值,选项),
o=选项,
内部={},
_i=内部;
_i、 container=$(this);//container
_i、 containerHeight=0;//容器
_i、 items=_i.container.children();//容器中的元素
_i、 w=_i.items.first().width();
_i、 列={};
_i、 colHeight={};
//设置容器及其子容器的位置
_i、 container.css({
“位置”:“相对”
}).children().css({
“位置”:“绝对”
});
//循环浏览所有项目,并按列将其放入数组中
_i、 项目。每个(功能(i){
var itemPlace=i%o.columns;//获取列
var col=itemPlace+1;//从1开始索引
如果(_i.列[col]==未定义){
_i、 columns[col]=[$(this)];//如果该列不存在,请创建它
}否则{
_i、 columns[col].push($(this));//否则将当前元素添加到正确的列中
}
var left=itemPlace*(_i.w+o.gutter);//计算列的左偏移量
$(this.css)({
“left”:left+px',//应用偏移量
“左边距”:0//并确保容器上没有左边距
});
});
//循环浏览现有列
对于(var x=1;x您的列生成器默认为三列(columns
在其defaults
对象中为3)。当您在“#projects”上调用它时,只有两篇文章。您的插件(在第50行,jquery.columnize.js)在一个只有两列的对象上从x=1循环到3。然后将一个空对象传递到jquery的each()函数,这是导致错误的原因。使用非精简版本的jQuery进行测试。您将获得更有意义的错误消息,并知道jQuery库中的哪行代码出现错误。Google实际上也通过CDN共享非精简版本,因此您所要做的就是删除“.min”从你的URL。非常感谢这个提示。我切换到非min版本,发现它是一个对象。长度错误,这有助于跟踪它(我现在看到你也这样做了)。谢谢。感谢这个解决方案,我在切换到非minified jquery版本后也能找到它(我不敢相信我以前从未做过…)无论如何,非常感谢。
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);