jquery – 在CSS选择器中使用&

我有一个id为masterResourceFor_R& D的div.但是当我在jQuery中使用这个ID来选择这个div并在其上放置一个click函数时,它不起作用.我认为这个问题是因为符号&在ID中.我没有任何重命名ID的选项.

我怎样才能在jQuery中使用这个ID?

最佳答案
忽略使用特殊字符作为id和类名称,如果可以,请更改它,如果你不能,并且你想要解决this混乱,你需要逃避该角色

#masterResourceFor_R\&D {
   color: red;
}

Demo

Reference

In CSS,identifiers (including element names,classes,and IDs in
selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646
characters U+00A0 and higher,plus the hyphen (-) and the underscore
(_); they cannot start with a digit,two hyphens,or a hyphen followed
by a digit. Identifiers can also contain escaped characters and any
ISO 10646 character as a numeric code (see next item). For instance,
the identifier “B&W?” may be written as “B\&W\?” or “B\26 W\3F”.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些