获取数组中所有选中的复选框 [英] Getting all selected checkboxes in an array
本文介绍了获取数组中所有选中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这些复选框:
<input type="checkbox" name="type" value="4" />
<input type="checkbox" name="type" value="3" />
<input type="checkbox" name="type" value="1" />
<input type="checkbox" name="type" value="5" />
等等.其中大约有 6 个并且是手工编码的(即不是从数据库中提取的),因此它们很可能会在一段时间内保持不变.
And so on. There are about 6 of them and are hand-coded (i.e not fetched from a db) so they are likely to remain the same for a while.
我的问题是如何将它们全部放入一个数组中(在 javascript 中),以便我可以在使用 Jquery 发出 AJAX $.post
请求时使用它们.
My question is how I can get them all in an array (in javascript), so I can use them while making an AJAX $.post
request using Jquery.
有什么想法吗?
我只想将选定的复选框添加到数组中
I would only want the selected checkboxes to be added to the array
推荐答案
Formatted :
Formatted :
$("input:checkbox[name=type]:checked").each(function(){
yourArray.push($(this).val());
});
希望它会奏效.
这篇关于获取数组中所有选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文