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 cho开发者_StackOverflow中文版pping away at my code to track these messages down. However, can anyone suggest what's provoking the warnings?
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).
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.
精彩评论