jQuery工具错误:未捕获错误:语法错误,无法识别的表达式:[href =/] [英] jquery tools error: Uncaught Error: Syntax error, unrecognized expression: [href=/]
问题描述
我刚刚将jQuery工具加载到我的网站上.但是Google Chrome控制台显示错误:
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)
我正在使用的jQuery版本是1.7.1
The jQuery version I am using is 1.7.1
如何处理此问题?
推荐答案
我假设您有一个选择器,该选择器用于匹配href
属性值为/
的元素.您需要将/
字符放在引号中
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=\\/]");
从 jQuery文档:
如果您希望将任何元字符(例如
!"#$%&'()*+,./:;<=>?@[\]^
{|}〜`)用作名称的文字部分,则必须使用两个反斜杠对字符进行转义:\\.
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.
这篇关于jQuery工具错误:未捕获错误:语法错误,无法识别的表达式:[href =/]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!