2017-04-25 13 views
0

這裏的參數是錯誤:無法插入新錶行與數據從功能

function_script_cashier.js:108 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
at AddMenuOnTable (function_script_cashier.js:108)
at HTMLButtonElement.onclick (cashier.php:1)

這裏是我的OnClick功能(從AJAX的回聲):

<button onclick="AddMenuOnTable(\''.$row['kode_menu'].'\',\''.$row['harga_jual'].'\')" class="btn btn-success">+</button> 

這是我的腳本:

function AddMenuOnTable(kode,harga){ 
    var tableRef = document.getElementById('whatToOrder').getElementsByTagName('tbody')[0]; 
    var newRow = tableRef.insertRow(tableRef.rows.length); 
    var cell_jumlah = newRow.insertCell(3); 
    var newText = String(harga); 
    cell_jumlah.className = "harga"; 
    cell_jumlah.appendChild(newText); 
} 

從上面的代碼中,我試圖將數據添加到表,但它始終返回錯誤 對不起我的英文不好,即時通訊新的網頁開發

回答

0

當您創建cell,然後使用appendChild()。所以改爲appendChild()你可以試試:

cell_jumlah.innerHTML = newText;