//表单组合为js对象数组 //1、表单元素的class_name为筛选条件 //2.表单元素的name属性是js对象的name属性的值 function GetJSObjectArr(class_name) { //作者:敖士伟 ikmb@163.com var a = []; //文本框 $("." + class_name).filter(":text").each(function(i) { //alert(this.name); //alert(this.value); a.push({ name: this.name, value: this.value }); }); //多列文本框 $("." + class_name).filter("textarea").each(function(i) { //alert(this.name); //alert(this.value); a.push({ name: this.name, value: this.value }); }); //下拉列表 $("." + class_name).filter("select").each(function(i) { //alert(this.name); //alert(this.value); a.push({ name: this.name, value: this.value }); }); //单选框 $("." + class_name).filter(":radio").filter(":checked").each(function(i) { //alert(this.name); //alert(this.value); a.push({ name: this.name, value: this.value }); }); //复选框开始 var temp_cb = ""; $("." + class_name).filter(":checkbox").filter(":checked").each(function(i) { if (temp_cb.indexOf(this.name) == -1) { temp_cb += this.name + ","; } }); var temp_cb_arr = temp_cb.split(","); var cb_name = ""; var cb_value = ""; for (var temp_cb_i = 0; temp_cb_i < temp_cb_arr.length - 1; temp_cb_i++) { cb_name = temp_cb_arr[temp_cb_i]; var cb_value_length = $("input[name='" + temp_cb_arr[temp_cb_i] + "']:checked").length; $("input[name='" + temp_cb_arr[temp_cb_i] + "']:checked").each(function(i) { if (i == cb_value_length - 1) cb_value += this.value; else cb_value += this.value + ","; }); //alert(cb_name); //alert(cb_value); a.push({ name: cb_name, value: cb_value }); } //复选框结束 return a; }