我有类似的东西:
<form id="my_form">
<input type="hidden" name="name_1" value="1">
<input type="text" name="name_2" value="text_1">
<input type="text" name="name_3" value="text_2">
<select name="name_4">
<option value="1">opt1</option>
<option value="2">opt2</option>
</select>
</form>
并在我的jQuery代码中:
$('#my_form').serializeArray().forEach(function(item){
// here 'item' has two props: 'name' and 'value'
// how can I select form's item based on name but NOT type HIDDEN ?
});
答案 0 :(得分:1)
您可以使用:not()
将您的选择器更改为
$('#my_form :not(:hidden)').serializeArray().forEach(function(item){
// here 'item' has two props: 'name' and 'value'
// how can I select form's item based on name but NOT type HIDDEN ?
});
答案 1 :(得分:0)
$('#my_form').find("input[type!='hidden']").serializeArray().forEach(function(item){
// here 'item' has two props: 'name' and 'value'
// how can I select form's item based on name but NOT type HIDDEN ?
});
答案 2 :(得分:0)
您可以使用jQuery not
选择器:
选择与给定选择器不匹配的所有元素。
代码:
$('#my_form :not([type=hidden])').serializeArray().forEach(function(item){
});