admin管理员组文章数量:1434908
Lets say I have a set of inputs on a form:
<form id="myform">
<input type="checkbox" id="goat_1">
<input type="checkbox" id="goat_2">
<input type="text" id="pig_3">
<input type="hidden" id="cow_1">
<input type="hidden" id="chick_3">
<input type="hidden" id="duck_5">
</form>
I want to select all inputs, except type="hidden"
, but with one exception I DO want any hidden input with an id beginning with "duck". I need this all in one array so I can iterate through it.
So the first two parts are easy:
$("#myform").find(":input").not("[type=hidden]").each(
function () { alert("do stuff"); })
But what about the exception?
I am looking for the cleanest way to do this (prefer one line/statement).
Lets say I have a set of inputs on a form:
<form id="myform">
<input type="checkbox" id="goat_1">
<input type="checkbox" id="goat_2">
<input type="text" id="pig_3">
<input type="hidden" id="cow_1">
<input type="hidden" id="chick_3">
<input type="hidden" id="duck_5">
</form>
I want to select all inputs, except type="hidden"
, but with one exception I DO want any hidden input with an id beginning with "duck". I need this all in one array so I can iterate through it.
So the first two parts are easy:
$("#myform").find(":input").not("[type=hidden]").each(
function () { alert("do stuff"); })
But what about the exception?
I am looking for the cleanest way to do this (prefer one line/statement).
Share Improve this question asked Aug 22, 2013 at 1:18 EkoostikMartinEkoostikMartin 6,9113 gold badges34 silver badges63 bronze badges2 Answers
Reset to default 7Try
$("#myform").find(":input").not("[type=hidden]:not([id^='duck'])").each(function () {
alert("do stuff");
});
Try this:
$('#myform > input').not(':hidden:not([id^=duck])').each(function (i, e) {
alert('This is my id: ' + e.id);
});
Working example in this fiddle.
本文标签: javascriptselect all inputs except hidden (but with one exception)Stack Overflow
版权声明:本文标题:javascript - select all inputs except hidden (but with one exception) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745627516a2667064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论