有“或”吗?属性选择器,如 input[type=button|text]?
我试图选择页面上的所有 input
元素,但不选择 image
、button
或 submit 类型的元素
。我首先想到的是选择所有 text
类型的 input
元素,然后选择所有 checkbox
类型的元素等。
但是,这不是'非常优雅。我想知道这里是否有更好的技术。有用的是像 input[type=text|checkbox|radio|password|etc]
这样的选择器,但这似乎不可用。
我知道我还可以选择所有输入,然后使用 .filter() 过滤它们,但是是否有更通用的选择器来选择具有属性列表之一的元素?
I'm trying to select all input
elements on a page, but not the ones that are of type image
, button
or submit
. What came to my mind first was selecting all input
elements that are of type text
, then all of type checkbox
etc.
However, this isn't very elegant. I was wondering if there is any better technique here. What would be useful is a selector like input[type=text|checkbox|radio|password|etc]
, but this does not seem to be available.
I know I can also select all input
s and then filter them using .filter()
but is there a more generic selector to select elements having one of a list of attributes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
由于您想要包含除少数特定类型之外的所有内容,请尝试以下操作:
Since you want to include everything except a few particular types, try this:
或(摘自评论)
or (taken from comments)
在 CSS 中你可以有这样的选择器:
也许这也适用于 jQuery。
In CSS you can have selectors like:
maybe this works in jQuery as well.
我知道它很旧,但我觉得最好的优雅解决方案是给他们一个公共类,然后将其用作选择器?
I know its old, but i feel the best elegant solution for this would be to give them a common class and then use that as a selector ?
上述答案并不完全正确。
当依赖于 id (#) 时,这些方法似乎会失败。
根据我的经验,我们需要为每个
or
语句添加 id。就像这样:
The above answers are not entirely true.
When depending on a id (#) these methods seems to fail.
In my experience we need to add the id for each
or
statement.Like so: