jquery - 获取输入和 select id 开始和结束的元素
jquery - get input and select elements with id start and ends with
我找到了如何获取 id 以 aName
开头并以 EditMode
结尾的元素,如下所示:jQuery selector for matching at start AND end of ID?
$('[id ^=aName][id $=EditMode]')
我还找到了如何获取类型为 input 和 select 的元素,如下所示:jQuery find input type (but also for select)
$('input, select');
我如何将这两者结合起来以获取 ID 以 aName
开头并以 EditMode
结尾的所有输入和 select 元素
Reduce the set of matched elements to those that match the selector or pass the function's test.
$('input, select').filter('[id^=aName][id$=EditMode]')....
或者,组合选择器
$('input[id^=aName][id$=EditMode], select[id^=aName][id$=EditMode]').....
您可以使用jquery filter()
方法:
$('input,select').filter('[id ^=aName][id $=EditMode]')
参见下面的演示:
console.log($('input,select').filter('[id ^=aName][id $=EditMode]').get());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="aName_1_EditMode"/>
<input type="text" id="aName_2_EditMode"/>
<input type="text" id="aName_3_EditMode"/>
<input type="text" id="aName_3_"/>
<input type="text" id="3_EditMode"/>
<select type="text" id="aName_4_EditMode">
<option value="1">1</option>
<option value="2">2</option>
</select>
我找到了如何获取 id 以 aName
开头并以 EditMode
结尾的元素,如下所示:jQuery selector for matching at start AND end of ID?
$('[id ^=aName][id $=EditMode]')
我还找到了如何获取类型为 input 和 select 的元素,如下所示:jQuery find input type (but also for select)
$('input, select');
我如何将这两者结合起来以获取 ID 以 aName
开头并以 EditMode
Reduce the set of matched elements to those that match the selector or pass the function's test.
$('input, select').filter('[id^=aName][id$=EditMode]')....
或者,组合选择器
$('input[id^=aName][id$=EditMode], select[id^=aName][id$=EditMode]').....
您可以使用jquery filter()
方法:
$('input,select').filter('[id ^=aName][id $=EditMode]')
参见下面的演示:
console.log($('input,select').filter('[id ^=aName][id $=EditMode]').get());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="aName_1_EditMode"/>
<input type="text" id="aName_2_EditMode"/>
<input type="text" id="aName_3_EditMode"/>
<input type="text" id="aName_3_"/>
<input type="text" id="3_EditMode"/>
<select type="text" id="aName_4_EditMode">
<option value="1">1</option>
<option value="2">2</option>
</select>