table2json html table 转换为 json
function getRseData() {
var aJsonObj = [];
$(tbl_rse.rows).each(function(i, row) {
if (i < $(tbl_rse.rows).size() - 1) {
var jsonStr = "{";
$(row.cells).each(function(j, cell) {
var name = "";
var value = "";
if (2 == j) {
var factorR = $(cell).children().eq(0);
var factorRname = factorR.attr("name").replace(/[^\.]+\./gi, '');
var factorRvalue = factorR.val();
jsonStr += '"' + factorRname + '":' + '"' + factorRvalue + '",';
?
var factorY = $(cell).children().eq(1);
var factorYname = factorY.attr("name").replace(/[^\.]+\./gi, '');
var factorYvalue = factorY.val();
jsonStr += '"' + factorYname + '":' + '"' + factorYvalue + '",';
?
var d = $(cell).children().eq(2);
var dName = d.attr("name").replace(/[^\.]+\./gi, '');
var dValue = d.val();
jsonStr += '"' + dName + '":' + '"' + dValue + '",';
} else if (7 == j) {
var factorR2 = $(cell).children().eq(0);
var factorR2name = factorR2.attr("name").replace(/[^\.]+\./gi, '');
var factorR2value = factorR2.val();
jsonStr += '"' + factorR2name + '":' + '"' + factorR2value + '",';
?
var factorY2 = $(cell).children().eq(1);
var factorY2name = factorY2.attr("name").replace(/[^\.]+\./gi, '');
var factorYvalue = factorY2.val();
jsonStr += '"' + factorY2name + '":' + '"' + factorYvalue + '",';
?
var d2 = $(cell).children().eq(2);
var d2Name = d2.attr("name").replace(/[^\.]+\./gi, '');
var d2Value = d2.val();
jsonStr += '"' + d2Name + '":' + '"' + d2Value + '",';
} else {
name = $(cell).children().first().attr("name").replace(/[^\.]+\./gi, '');
value = $(cell).children().first().val();
jsonStr += '"' + name + '":' + '"' + value + '",';
}
});
jsonStr = jsonStr.replace(/,{1}$/gi, '');
jsonStr += "}";
var jsonObj = jQuery.parseJSON(jsonStr);
aJsonObj.push(jsonObj);
// console.log("jsonStr=" + jsonStr);
}
});
// console.log("aJsonObj=" + aJsonObj);
// console.log("aJsonObj.length=" + aJsonObj.length);
?
return aJsonObj;
}