Ray*_* S. 9 jquery select jquery-selectors
什么是迭代所有选择下拉列表的最简单方法,ID使用jquery匹配模式.例如:
<select id="begin_1_end">...</select>
<select id="begin_32_end">...</select>
<select id="begin_42_end">...</select>
<select id="dontgetme_2_end">...</select>
<select id="begin_12_dontgetme">...</select>
Run Code Online (Sandbox Code Playgroud)
迭代前3个选择.
Ant*_*ton 28
尝试使用attribute-starts-with-selector /
$('select[id^="begin"]').each(function () {
console.log(this.id);
});
Run Code Online (Sandbox Code Playgroud)
或者您可以使用 attribute-ends-with-selector
$('select[id$="end"]').each(function () {
console.log(this.id);
});
Run Code Online (Sandbox Code Playgroud)
更新
要选择前3个,你可以:lt(3)像这样使用
$('select[id^="begin"]:lt(3)').each(function () {
console.log(this.id);
});
Run Code Online (Sandbox Code Playgroud)
更新
要组合选择器,您可以执行此操作
$('select[id^="begin"][id$="end"]').each(function () {
console.log(this.id);
});
Run Code Online (Sandbox Code Playgroud)
如果要选择id以begin OR结尾的元素,可以使用,两个不同的选择器
$('select[id^="begin"],select[id$="end"]').each(function () {
// ^
console.log(this.id);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25784 次 |
| 最近记录: |