我有以下HTML标签,并希望通过jQuery选择它们:
<div foo:bar="test"></div>
<span foo:bar="test2"></span>
<xxx foo:bar="test3"></xxx>
Run Code Online (Sandbox Code Playgroud)
所以,我想选择具有该属性的所有标签foo:bar.
我试过以下:
$('[foo:bar]').addClass("fooBar");
// Error: Syntax error, unrecognized expression: [adv:sensorid]
Run Code Online (Sandbox Code Playgroud)
我知道,正确的语法将类似于"data-foo-bar",但我必须使用"foo:bar".
这在jQuery中甚至可能吗?
我甚至可以使用AngularJS,如果它有所帮助.非常感谢你!
这是可能的.你需要逃避任何特殊角色\\
$('[foo\\:bar]').addClass("fooBar");
Run Code Online (Sandbox Code Playgroud)
要使用任何元字符(例如!"#$%&'()*+,./:; <=>?@ [] ^`{|}〜)作为名称的文字部分,必须使用两个反斜杠进行转义:\\.例如,id ="foo.bar"的元素可以使用选择器$("#foo \\.bar").
| 归档时间: |
|
| 查看次数: |
1183 次 |
| 最近记录: |