我如何追踪这些 Firefox 警告消息?

发布于 2024-10-11 20:41:47 字数 469 浏览 3 评论 0原文

自从升级到 jQuery 1.4.4 以来,当我在 Firefox 3.6.13 中运行单元测试时,我收到了几条新的警告消息。这是一个典型的:

Warning: Unexpected token in attribute selector: '!'.
Source File: http://localhost/unitTests/devunitTests.html
Line: 0

或者更有用的:

Warning: Selector expected.
Source File: http://localhost/unitTests/ui/editors/iframe2.html?test=15
Line: 0

网页渲染得很好,而且我所有的 JavaScript 代码似乎也运行得很好,所以我不愿意花大量的时间来修改我的代码来跟踪这些代码消息已下。但是,有人能指出是什么引起了警告吗?

Since I upgraded to jQuery 1.4.4 I've been getting several new warning messages when I run my unit tests in Firefox 3.6.13. Here's a typical one:

Warning: Unexpected token in attribute selector: '!'.
Source File: http://localhost/unitTests/devunitTests.html
Line: 0

Or the even more useful:

Warning: Selector expected.
Source File: http://localhost/unitTests/ui/editors/iframe2.html?test=15
Line: 0

The web page renders nicely, and all my JavaScript code seems to be running okay too, so I'm reluctant to spend a potentially large amount of time chopping away at my code to track these messages down. However, can anyone suggest what's provoking the warnings?

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

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

发布评论

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

评论(2

无畏 2024-10-18 20:41:47

你可能有这样的东西:

$(selectorVariable)

...以及其他类似的东西:

$("something[" + attributeNameVariable + "!=somethingElse]")

在这两种情况下,你的变量为空都会出错,因为 """selector[!=value]" 不是有效的选择器。只需查看您是否在选择器中使用变量,并添加 if() 检查,以便在这些情况下选择器无效时它们不会运行(有时变量中的空字符串就可以了) ,取决于它的使用地点)。

You likely have something like this:

$(selectorVariable)

...and something else along these lines:

$("something[" + attributeNameVariable + "!=somethingElse]")

in both these cases your variables being empty would error, since "" and "selector[!=value]" aren't valid selectors. Just look were you're using variables in selectors, and add if() checks so they don't run if the selector would be invalid in those cases (sometimes an empty string in the variable is just fine, depends where it's being used).

回忆追雨的时光 2024-10-18 20:41:47

基本上,Firefox对javascript有严格的规定,会在不影响javascript代码运行的小问题上返回错误。在我的脑海中,定义没有 var 的变量会在错误控制台中创建某种警告,尽管这样做是完全可以的。这些编码实践对于缩小 javascript 并使 javascript 整体更精简且运行得更快来说是正常的 - 您会注意到大多数这些错误实际上发生在 jQuery 本身中。

您可以在此处阅读有关 Firefox 严格 javascript 错误的更多信息: http://www.howtocreate.co.uk/ strictJSFirefox.html

可以关闭严格警告,但在开发时可能不建议这样做。

TL;DR:如果一切正常,就不用担心他们,FF 只是太挑剔了。

Basically, Firefox has strict rules for javascript and will return errors on trivial matters that do not affect the javascript code from running. Off the top of my head defining variables without var will create some sort of warning in the error console, although it is perfectly fine to do so. These sort of coding practices are normal for minifying javascript and making javascript overall leaner and run faster - you will notice that most of these errors actually occur in jQuery itself.

You can read more on Firefox strict javascript errors here: http://www.howtocreate.co.uk/strictJSFirefox.html

It is possible to turn off strict warnings, but probably not advisable while you are developing.

TL;DR: Don't worry about them if everything works, FF is just overly fussy.

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