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

孤者浪人 提交于 2019-12-08 15:24:37

问题


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?


回答1:


Quote the value:

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

http://jsfiddle.net/7Pqhc/




回答2:


Put the attribute in quotes

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



回答3:


[name='Basics.Gender']

Have you tried with quotes?




回答4:


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>


来源:https://stackoverflow.com/questions/11849104/jquery-syntax-error-unrecognized-expression-name-basics-gender

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