jQuery 语法错误,无法识别的表达式:[name=Basics.Gender]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11849104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:59:24  来源:igfitidea点击:

jQuery Syntax error, unrecognized expression: [name=Basics.Gender]

jquerysizzle

提问by superlogical

I am upgrading from jQuery 1.4.4 to jQuery 1.7.2 and I get a syntax error. I think its due to the '.' in the Basics.Gender part of the selector.

我正在从 jQuery 1.4.4 升级到 jQuery 1.7.2,但出现语法错误。我认为这是由于“。” 在选择器的 Basics.Gender 部分。

$('[name=Basics.Gender]')

Anyone have any suggestions on how to fix this?

有人对如何解决这个问题有任何建议吗?

http://jsfiddle.net/2nBc9/

http://jsfiddle.net/2nBc9/

EDIT

编辑

Anyone know why the '.' breaks the selector syntax now? Are they using regex's or something in Sizzle? Or has it always been best practice to put the attribute in quotes?

任何人都知道为什么'.' 现在打破选择器语法?他们是否在 Sizzle 中使用正则表达式或其他东西?还是将属性放在引号中一直是最佳实践?

回答by Esailija

Quote the value:

引用值:

$('div[name="Basics.Gender"]')

http://jsfiddle.net/7Pqhc/

http://jsfiddle.net/7Pqhc/

回答by Rocket Hazmat

Put the attribute in quotes

将属性放在引号中

$('[name="Basics.Gender"]')

回答by JNDPNT

[name='Basics.Gender']

Have you tried with quotes?

你试过引号吗?

回答by jeff

Put the attribute in quotes. The following prints "TEST" in the console:

将属性放在引号中。以下在控制台中打印“TEST”:

jQuery:

jQuery:

$(document).ready(function() {
    console.log($("[name='Basics.Gender']").text());
});

HTML:

HTML:

<div name="Basics.Gender">TEST</div>