让所有选定的复选框中的数组 [英] Getting all selected checkboxes in an array
本文介绍了让所有选定的复选框中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我有这些复选框:
So I have these checkboxes:
<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,并手工codeD(即不是从数据库中取出),所以他们很可能会保持不变一段时间。
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 $。交
的要求。
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
推荐答案
格式化:
$("input:checkbox[name=type]:checked").each(function(){
yourArray.push($(this).val());
});
希望,它将工作。
Hopefully, it will work.
这篇关于让所有选定的复选框中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文