2011-06-08 71 views
1

我想用jQuery Lint检查可能的jQuery错误。jQuery Lint错误是相当不具描述性的

我想试用一个简单的脚本,它的工作原理。我把jquery lint包括在内,把它设置为2级,而BAM则有3个错误。

jQuery(.highlightimage) special check failed 

jquery.lint.js (line 100) 

More info: 

Selector: .highlightimage Selectors should be as specific as possible and should be "class only" 

Collection: [] 

Location: 

@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 

@http://localhost:53402/Resources/Scripts/highlights.js:15 

@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 

@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 

什么?第15行是:

hl_elements = $(".highlightimage"); 

那个错误是什么意思?选择器包含5个元素,因此它是有效的。它尽可能具体。

它在$(document).ready(function(){/ 这里是脚本 /});部分。

我的所有选择器都是这样失败的。我究竟做错了什么?

我正在使用jquery 1.6.1,它可能还不支持,但在github上已经有jquery 1.6.1的测试用例,并且它们工作正常。

其他错误是:

trigger(ready) called incorrectly 
jquery.lint.js (line 100) 

More info: 
Collection: [Document localhost:53402] 

Location: 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 
jquery.lint.js (line 115) 
You passed: ["ready"] 

Available signatures include: 
trigger(eventType, extraParameters) 
trigger(event) 

我得到的页面加载。

每当图像被改变时,我都会得到另一个。

jQuery.removeData([object HTMLImageElement],fxqueue,true) called incorrectly 
jquery.lint.js (line 100) 

More info: 
Location: 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:18 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:18 
jquery.lint.js (line 115) 
You passed: [img.highlightimage /Documen..._293.png, "fxqueue", true] 

Available signatures include: 
jQuery.removeData(element, [name]) 

但是,如果我切换到jquery 1.4.4这最后一个不会发生。

+0

有时候立即上方或下方有一个错误,但我不能告诉你更多没有一些代码片段:) – 2011-06-08 08:46:36

+0

http://jsfiddle.net/SoonDead/fMcrb/这是我的代码,我也使用jquery 1.6.1 – SoonDead 2011-06-08 12:35:35

回答

3

的源代码在https://github.com/jamespadolsey/jQuery-Lint/blob/551c2106ac0daee95a670fb180610d09e58bb4cc/jquery.lint.js#L711说:

//查找类只选器(差 IE6-8性能)

所以我想这是对警告的原因。如果你想使用类选择器,那么我会认为你可以忽略它。

(我假设的错误文本应该说“不应该‘类只’”)。

+0

这当然不容易解释。也许通过“只有班级”,他们意味着你不应该做“div.whatever”(而不是“class”),而是“尽可能具体”,这意味着你应该做“#specificarea”。不管“以避免搜索整个文档。 – 2011-06-08 09:16:50

+0

这实际上帮了很多!谢谢,但遗憾的是还有其他错误。我在上面的评论上发布了jsfiddle。 – SoonDead 2011-06-08 12:44:00