這是我的JavaScript函數。如何使用JavaScript僅在tbody中添加數據
function SaveCustomdata() {
var customName = document.getElementById("lblNAME").value;
var customEmail = document.getElementById("lblEmail").value;
var customContectNo = document.getElementById("lblContectNO").value;
var row = "";
row += '<tr><td>' + customName + '</td><td>' + customEmail + '</td><td>' + customContectNo + '</td></tr>';
document.getElementById("Customdata").appendChild(row);
}
HTML代碼,我想數據
<table>
<thead>
<tr>
<th style=" color:#01A0DF; padding-right:60px;">Name</th>
<th style=" color:#01A0DF; padding-right:70px;">Email</th>
<th style=" color:#01A0DF; padding-right:90px;">Contect/Mobile No</th>
<td>
<input type="button" id="btnclick" value="Add" onclick="AddRecord()" />
</td>
</tr>
</thead>
<tbody id="Customdata"></tbody>
</table>
追加獲得一個錯誤
0x800a139e - JavaScript run time error: Hierarchy Request Error
您需要的元素傳遞給'的appendChild()'不是一個字符串。 (使用'document.createElement(「tr」)'先創建一個,更新它,追加它) –
你實際上必須用JS創建元素。你不能只使用jQuery來追加一個字符串。 http://www.w3schools.com/js/js_htmldom_nodes.asp – Gavin
@Gavin http://www.w3fools.com/ –