当值包含美元符号时,如何通过属性值选择元素? [英] How to select elements by attribute's value when values contains dollar sign?
问题描述
我有以下HTML元素:
I have the following HTML element:
<input type="checkbox" name="ctl00$ContentPH$ucFuncionEdit1$ckEsMenu" />
如何使用jQuery选择具有相同名称的所有元素,以下操作失败:
How can I select all elements with the same name using jQuery, the following fails:
jQuery('[name=ctl00$ContentPH$ucFuncionEdit1$ckEsMenu]');
上一行代码会引发以下错误:
The previous line of code raise the following error:
错误:语法错误,无法识别的表达式: [name = ctl00 $$ ContentPH $$ ucFuncionEdit1 $$ ckEsMenu]
Error: Syntax error, unrecognized expression: [name=ctl00$$ContentPH$$ucFuncionEdit1$$ckEsMenu]
推荐答案
您引用值:
jQuery ('[name="ctl00$ContentPH$ucFuncionEdit1$ckEsMenu"]');
在处理属性选择器时,最好始终引用该值(尽管如果该值是一个仅包含 字母AZ [不区分大小写]和数字0-9 [但不包含]的单词以数字开头],那么您就可以摆脱困境).
When dealing with attribute selectors, it's best to always quote the value (although if the value is a single word containing only the letters A-Z [case insensitive] and the digits 0-9 [but not starting with a digit], you can get away without).
这篇关于当值包含美元符号时,如何通过属性值选择元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!