js 多个input值拼接json字符串
如果所有的标签都在form内,就可以用$('#YourFormId').serializeArray();
如果没有form,就可以用下面的方法
var ID = $("input[name='ID']").val();
var name = $("input[name='name']").val();
var date = $("#spdate").find("input").val();
var safe = $("input[name='safe']").val();
var NUM = $("#spbatch").find("input").val();
var WANRR = $("input[name='WANRR']").val();
var WANRG = $("input[name='WANRG']").val();
var WANRY = $("input[name='WANRY']").val();
var PTimes = $("#spprint").find("input").val();
var result = '{ "ID":" ' + ID + '","name":"' + name + '","date":"' + date + '","safe":"' + safe + '","NUM":"' + NUM + '","WANRR":"' + WANRR + '","WANRG":"' + WANRG + '","WANRY":"' + WANRY + '","PTimes":"' + PTimes + '"}';
//var params = [];
//params.push({ "ID": ID, "name": name });
//params.push({ "date": date, "safe": safe });
//params.push({ "NUM": NUM, "WANRR": WANRR });
//params.push({ "WANRG": WANRG, "WANRY": WANRY });
//params.push({ "PTimes": PTimes });
//var json = JSON.stringify(params);
//var e = new RegExp("{", "g");
//json = json.replace(e, "");
//e = new RegExp("}", "g");
//json = json.replace(e, "");
//json = json.replace("[","{").replace("]","}");
搜索关注微信号amcdulls,或程小白 ,同步更新博文