/**
*序列化form表单元素为对象
* @param target form对应的jquery对象/jquery选择器
* @param isPostEmpty 设置空值字段是否序列化
* @author jdh
*/
serializeObject: function(target,isPostEmpty){
var tempPostData = {}, attrArray = $(target).serializeArray();
$.each(attrArray,function(index,attrObj){
if(tempPostData[attrObj.name]){
if($.isArray(tempPostData[attrObj.name])) {
tempPostData[attrObj.name].push(attrObj.value);
}else{
tempPostData[attrObj.name] = [tempPostData[attrObj.name],attrObj.value];
}
}else if(!!isPostEmpty || !!attrObj.value) {
tempPostData[attrObj.name] = attrObj.value;
}
})
return tempPostData;
*序列化form表单元素为对象
* @param target form对应的jquery对象/jquery选择器
* @param isPostEmpty 设置空值字段是否序列化
* @author jdh
*/
serializeObject: function(target,isPostEmpty){
var tempPostData = {}, attrArray = $(target).serializeArray();
$.each(attrArray,function(index,attrObj){
if(tempPostData[attrObj.name]){
if($.isArray(tempPostData[attrObj.name])) {
tempPostData[attrObj.name].push(attrObj.value);
}else{
tempPostData[attrObj.name] = [tempPostData[attrObj.name],attrObj.value];
}
}else if(!!isPostEmpty || !!attrObj.value) {
tempPostData[attrObj.name] = attrObj.value;
}
})
return tempPostData;
}
$.fn.serializeObject = function() {
var o = {};
var dataArray = this.serializeArray();
$.each(dataArray, function(i, item) {
if (o[item.name]) {
if (!o[item.name].push) {
o[item.name] = [o[item.name]];
}
o[item.name].push(_jsonValue(item.value));
} else {
o[item.name] = _jsonValue(item.value);
}
});
return o;
};