jquery tools error: Uncaught Error: Syntax error, unrecognized expression: [href=/]

佐手、 提交于 2019-12-20 05:02:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!