我遇到一些JS代码更改我的divs类的情况:
<div class="form signed">
变为
<div class="signed form-sml">
我正在尝试选择此div中的所有输入字段:
$(".form, .form-sml :input)
这将选择form-sml输入,但不选择表单输入。如何选择两者?
答案 0 :(得分:3)
jQuery supports multiple selection使用逗号分隔您的各个选择器,这将选择满足任一选择器的元素,如下所示:
+----------------------+---------------+-------------+-----------------------+-------------+-----------+----------+
+ Schedule + Email + Subject + Message + Bounced + Click + Open +
+----------------------+---------------+-------------+-----------------------+-------------+-----------+----------+
+ 04/22/2015 18:00:00 + abc@abc_17.com+ Hi + email template content+ 1 + 0 + 0 +
+----------------------+---------------+-------------+-----------------------+-------------+-----------+----------+
+ 04/25/2015 14:00:00 + def@gmail.com + Hi + email template content+ 0 + 1 + 1 +
+----------------------+---------------+-------------+-----------------------+-------------+-----------+----------+
同样,如果你知道你的类名将以“form”开头,你可以使用starts-with selector ^=
来处理相同的场景:
// This should select all <input> elements within either 'form' or 'form-sml' classes
$('.form :input,.form-sml :input')
示例强>
您可以see a working example here看到以下内容:
答案 1 :(得分:1)
$(".form :input, .form-sml :input)
应该这样做......