jQuery Syntax error, unrecognized expression: [nam

2019-06-15 12:50发布

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.

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

Anyone have any suggestions on how to fix this?

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?

标签: jquery sizzle
4条回答
走好不送
2楼-- · 2019-06-15 13:07

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

jQuery:

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

HTML:

<div name="Basics.Gender">TEST</div>
查看更多
家丑人穷心不美
3楼-- · 2019-06-15 13:22

Quote the value:

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

http://jsfiddle.net/7Pqhc/

查看更多
Juvenile、少年°
4楼-- · 2019-06-15 13:31

Put the attribute in quotes

$('[name="Basics.Gender"]')
查看更多
Emotional °昔
5楼-- · 2019-06-15 13:32
[name='Basics.Gender']

Have you tried with quotes?

查看更多
登录 后发表回答