微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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”.

原文地址:https://www.jb51.cc/html/426824.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐