pim*_*vdb 38 jquery jquery-selectors
我正在尝试选择input
页面上的所有元素,但不是那些类型的元素image
,button
或者submit
.我首先想到的是选择所有input
类型的元素text
,然后选择所有类型的元素checkbox
等.
但是,这不是很优雅.我想知道这里是否有更好的技术.有用的是选择器input[type=text|checkbox|radio|password|etc]
,但这似乎不可用.
我知道我也可以选择所有input
s然后使用它们进行过滤.filter()
但是是否有更通用的选择器来选择具有属性列表之一的元素?
Mic*_*ren 49
由于您希望包含除少数特定类型之外的所有内容,请尝试以下操作:
$('input:not([type=image],[type=button],[type=submit])')
Run Code Online (Sandbox Code Playgroud)
dru*_*dge 28
$('input[type=text], input[type=checkbox], input[type=radio]').stuff();
Run Code Online (Sandbox Code Playgroud)
或(取自评论)
$('input:not([type=image],[type=button],[type=submit]')
Run Code Online (Sandbox Code Playgroud)
在CSS中,您可以选择以下内容:
input[type=text],input[type=checkbox],input[type=radio],input[type=password]
Run Code Online (Sandbox Code Playgroud)
也许这也适用于jQuery.
归档时间: |
|
查看次数: |
27862 次 |
最近记录: |