jquery获取多个输入框name[id]这种数组的一种方式

html代码:

<input type="text" name="sort[1]" value="1" />

<input type="text" name="sort[2]" value="2" />

<input type="text" name="sort[3]" value="3" />

 

javascript代码:

 

<script>
$(function() {
//在 form 标记中就这样
$.post(location, $('form').serialize(), function(d) {alert(d)});

//不在 form 标记中就这样
d = {};
$("input[name^='sort']").each(function(i, el) {
d[el.name] =$(this).val();
});
$.post(location, {data:d}, function(d) {alert(d)});
});
</script>

 

 

 

 

觉得好的话记得打赏赞助小灰灰哦,小灰灰灰更有动力的,谢谢

小灰灰

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: