//获取页面表单数据转换为json对象
function get_form_to_json(myform){
var $form=$(myform);
var x=$form.serializeArray();
var $radio = $('input[type=radio],input[type=checkbox]', $form);//处理radio checkbox未选中 不能序列化的问题
var temp = {};
$.each($radio, function () {
if (!temp.hasOwnProperty(this.name)) {
if ($("input[name='" + this.name + "']:checked").length == 0) {
temp[this.name] = "";
x.push({name: this.name, value: "无"});
}
}
});
var jdata={};
$.each(x, function(i, field){
jdata[field.name]=field.value;
});
var mydata=JSON.stringify(jdata);
return mydata;
}
function get_form_to_json(myform){
var $form=$(myform);
var x=$form.serializeArray();
var $radio = $('input[type=radio],input[type=checkbox]', $form);//处理radio checkbox未选中 不能序列化的问题
var temp = {};
$.each($radio, function () {
if (!temp.hasOwnProperty(this.name)) {
if ($("input[name='" + this.name + "']:checked").length == 0) {
temp[this.name] = "";
x.push({name: this.name, value: "无"});
}
}
});
var jdata={};
$.each(x, function(i, field){
jdata[field.name]=field.value;
});
var mydata=JSON.stringify(jdata);
return mydata;
}