jQuery批量獲取input的val,並根據name屬性生成對應json物件的屬性
阿新 • • 發佈:2019-01-24
//統一獲取引數val
$.fn.serializeDIV = function () {
var o = {};
var a = $('[name]',this);
$.each(a, function () {
if (o[this.name]) {
o[this.name]+=","+(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
function getJson(id){
return$(id).serializeDIV();
}
var homeJson = getJson("#home");//獲取投資計劃
var ProjectBiddingJson = getJson("#ProjectBidding");//獲取工程計劃招標
var DesignJson = getJson("#Design");//獲取初步設計
var DrawDesignJson = getJson("#DrawDesign");//獲取施工圖初步設計
var ProjectAcceptJson = getJson("#ProjectAccept");//獲取工程驗收
var pname = $("#pname").val();//獲取專案名稱
var pid = $("#pid").val();//獲取專案編號
$.fn.serializeDIV = function () {
var o = {};
var a = $('[name]',this);
$.each(a, function () {
if (o[this.name]) {
o[this.name]+=","+(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
function getJson(id){
return$(id).serializeDIV();
}
var homeJson = getJson("#home");//獲取投資計劃
var ProjectBiddingJson = getJson("#ProjectBidding");//獲取工程計劃招標
var DesignJson = getJson("#Design");//獲取初步設計
var DrawDesignJson = getJson("#DrawDesign");//獲取施工圖初步設計
var ProjectAcceptJson = getJson("#ProjectAccept");//獲取工程驗收
var pname = $("#pname").val();//獲取專案名稱
var pid = $("#pid").val();//獲取專案編號