在jquery中选择具有不同类的元素
我可以一次选择不同类的元素吗 如果我有在jquery中选择具有不同类的元素,jquery,Jquery,我可以一次选择不同类的元素吗 如果我有 <div id="divAdd"> <p style="font-size:16px; color:Blue; "></p> <p class="test"> <input:textbox id="id1" type:"text" /> </p> <p class="tes
<div id="divAdd">
<p style="font-size:16px; color:Blue; "></p>
<p class="test">
<input:textbox id="id1" type:"text" />
</p>
<p class="test">
<input id="txtMobile" type="text" style="width:120px;" name="txtMobile">
</p>
<p class="test">
<input id="txtMobile" type="text" style="width:120px;" name="txtMobile">
</p>
<p class="child">
<input id="txtMobile" type="text" style="width:120px;" name="txtMobile">
</p>
我可以用这种方式选择两个不同类中的所有文本框吗
$('#divAdd .test input:text','#divAdd .child input:text').each(function () {
count++;
});
</div>
$('#divAdd.test输入:text','#divAdd.child输入:text')。每个(函数(){
计数++;
});
只需尝试:
$('#divAdd .test input:text, #divAdd .child input:text')
或为了获得更好的性能:
$('#divAdd').find('.test, .child').find('input:text')
试一下:
$('#divAdd .test input:text, #divAdd .child input:text')
或为了获得更好的性能:
$('#divAdd').find('.test, .child').find('input:text')
此处不需要引号,可以使用逗号
,
分隔:
$('#divAdd .test input:text, #divAdd .child input:text').each(function () {
还请注意:
<input:textbox id="id1" type:"text" />
不是有效的HTML标记,您需要删除此处的文本框。您不需要此处的引号,您可以使用逗号
,
分隔:
$('#divAdd .test input:text, #divAdd .child input:text').each(function () {
还请注意:
<input:textbox id="id1" type:"text" />
不是有效的HTML标记,您需要在此处删除
:文本框。您不需要,'
。您只需要一个,
$('#divAdd .test input:text,#divAdd .child input:text')
只需使用,
来分隔选择器。您不需要,
。您只需要一个,
$('#divAdd .test input:text,#divAdd .child input:text')
只需使用,
来分隔选择器。您也可以使用
旁注:文本框id必须是唯一的 您也可以使用
旁注:文本框id必须是唯一的 试试这个,用双引号
$("#divAdd .test input:text,#divAdd .child input:text").each(function () {
或
试试这个,用双引号
$("#divAdd .test input:text,#divAdd .child input:text").each(function () {
或