作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好吧,我已经使用 JQuery 一段时间了,我正在检查一些代码并尝试使其更简写(我正在处理的一个 JS 文件有 2000 多行)一页的 JQuery :S)。
这是我的问题,是否可以执行诸如 Or
选择器之类的操作?像这样的东西:
$("#element1Id and #element2Id")
我知道我可以使用模式匹配
$("[id^=element][id&=Id]")
但问题是,我的页面上有很多东西可以与我有问题的 ID 选择器匹配,我一直想知道你是否可以这样做或那样,我在其他情况下需要它。
有什么想法吗?
最佳答案
$('#element1Id, #element2Id')
<小时/>
Description: Selects the combined results of all the specified selectors.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order. An alternative to this combinator is the .add() method.
关于选择器中的 JQuery "OR"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10248671/
我是一名优秀的程序员,十分优秀!