1
我寫了一個代碼來獲取用戶選擇的值的詳細信息。該代碼工作正常,並顯示數組。唯一的問題是顯示錯誤的孩子節點。我在哪裏做錯了?迭代表中的多個行的值
function add_checkout_details(){
var total = $("#total").val();
var product_id = new Array();
var qty = new Array();
var price = new Array();
var amount = new Array();
var table = document.getElementById('myTable');
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var txtBox0 = row.cells[0].innerHTML;
var txtBox1 = row.cells[2].childNodes[0].value;
var txtBox2 = row.cells[3].childNodes[0].value;
var txtBox3 = row.cells[4].childNodes[0].value;
var txtBox4 = row.cells[8].childNodes[0].value;
product_id.push(txtBox0);
qty.push(txtBox1);
price.push(txtBox2);
amount.push(txtBox3);
}
$.post('controller/add_checkout_details.php',{'product_id[]':product_id,'qty[]':qty,'price[]':price,'amount[]':amount,total:total}, function(data){
$('#error').text(data);
});
}
你可以添加你的表在代碼中的樣子嗎? –