gpt4 book ai didi

选择器中的 JQuery "OR"?

转载 作者:行者123 更新时间:2023-12-01 02:13:39 24 4
gpt4 key购买 nike

好吧,我已经使用 JQuery 一段时间了,我正在检查一些代码并尝试使其更简写(我正在处理的一个 JS 文件有 2000 多行)一页的 JQuery :S)。

这是我的问题,是否可以执行诸如 Or 选择器之类的操作?像这样的东西:

$("#element1Id and #element2Id")

我知道我可以使用模式匹配

$("[id^=element][id&=Id]")

但问题是,我的页面上有很多东西可以与我有问题的 ID 选择器匹配,我一直想知道你是否可以这样做或那样,我在其他情况下需要它。

有什么想法吗?

最佳答案

$('#element1Id, #element2Id')
<小时/>

<强> Multiple Selector

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com