问题
I just loaded jQuery Tools onto my site. But the Google Chrome console shows an error:
Uncaught Error: Syntax error, unrecognized expression: [href=/] (http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js)
The jQuery version I am using is 1.7.1
How to deal with this problem?
回答1:
I'm assuming you have a selector that is meant to match elements with an href
attribute value of /
. You will need to put the /
character in quotes:
var elems = $("[href='/']");
Alternatively, you can escape the character:
var elems = $("[href=\\/]");
From the jQuery docs:
If you wish to use any of the meta-characters ( such as
!"#$%&'()*+,./:;<=>?@[\]^
{|}~` ) as a literal part of a name, you must escape the character with two backslashes: \\.
Here's a working example. Remove the quotes to generate the same error you mention in your question.
回答2:
My guess is that you changed the order of the libraries. If you want to use JQuery, its lib has to be loaded first to use an additional JQuery-Expansion-Lib. You should change the order in the <head>
like this:
<html>
<head>
<link rel="stylesheet" type="text/css" href="formate.css"> //CSS always first
<script src="URL_TO_JQUERY" type="text/javascript"></script> //JQuery first
<script src="URL_TO_ADDITIONAL_LIB_1" type="text/javascript"></script>
<script src="URL_TO_ADDITIONAL_LIB_..." type="text/javascript"></script>
<script src="URL_TO_ADDITIONAL_LIB_n" type="text/javascript"></script>
</head>
</html>
来源:https://stackoverflow.com/questions/13438945/jquery-tools-error-uncaught-error-syntax-error-unrecognized-expression-href