答案 0 :(得分:2)
在其中一个循环中添加if语句......
var sel = $(trs[i].children[j]).find("select");
if (sel.length == 0) {
keys.push(trs[i].children[j].innerHTML);
} else {
keys.push(sel.val());
}
它会生成此结果:
[{"1":"0","id":"0","value2":"0"},
{"1":"1.5","id":"0","value2":"2.15"}]
Demo。这就是你想要的吗?