[英]how to get all checked checkboxes from a dynamically generated form in the order
I have written a code which retrives all values of elements within a form its working with radio button, text boxes , dropdown , text area .but now i want to add checkboxes the problem is with checkboxes we can have multiple values for a particular name,so need to get the checkboxes values in order as they apper in the form 我已经编写了一个代码,该代码可以使用单选按钮,文本框,下拉列表,文本区域来检索表单中元素的所有值。但是现在我想添加复选框,问题在于复选框中,我们可以为特定名称使用多个值,因此需要按表格中的顺序获取复选框值
Here is the code to get the values: 这是获取值的代码:
var elements="";
var $this = jQuery(this);
$this.parents(".detailTable").find(":input").each(function(index, elm){
if((jQuery(this).attr("type")=="button") ||(jQuery(this).attr("type")=="hidden"))
{
}else if((jQuery(this).attr("type")=="radio")){
if(jQuery(this).attr("checked")){
elements=elements + (jQuery(this).val());
elements=elements + "|";
// alert(jQuery(this).val())
}
}else if((jQuery(this).attr("type")=="checkbox")){
if(jQuery(this).attr("checked")){
elements=elements + (jQuery(this).val());
elements=elements + "|";
}
}
else{
elements=elements + (jQuery(this).val());
elements=elements + "|";
// alert(jQuery(this).val());
}
});
I want all the values of a checkbox group comma seperated(form can have multiple checkboxes) while between elements the values are '|' 我希望用逗号分隔复选框组的所有值(窗体可以有多个复选框),而元素之间的值是“ |” seprated.
分开。
Can you help me with this 你能帮我吗
try using the .map()
method.. 尝试使用
.map()
方法。
var checkedBoxes= $('input[type=checkbox]:checked').map(function() {
return this.value ;
}).get().join('|');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.