我用insertAfter
(根據How to do insert After() in JavaScript without using a library?),但是,在我的情況下,它不起作用。javascript insertAfter不起作用
爲什麼?
<!doctype html>
<html lang="en">
<head></head>
<body>
<table id="myTable">
<tbody>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<script>
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
_table = document.getElementById("myTable");
_tbody = _table.getElementsByTagName("tbody")[0];
n = _tbody.getElementsByTagName("TR").length;
_referenceNode = _tbody.getElementsByTagName("TR")[n - 1]
_newTR = "<tr><td>A very complex table<td></td><td>much more complex than in this example</td></tr>";
parser = new DOMParser()
_newNode = parser.parseFromString(_newTR, "text/xml");
insertAfter(_newNode, _referenceNode);
</script>
</body>
</html>
[你真的只是問這個問題詢問(http://stackoverflow.com/questions/35758680/how-to-fix-this-javascript-error-當創造-A-復表動態地)。你想成爲被禁止的問題嗎?因爲刪除和重新分析問題就是你如何得到禁止的問題。 –
你只能使用appendChild。你爲什麼要做所有這些事情? –