修改DIV innerHTML会剥离表标记



单击按钮,我想将额外的表行和单元格添加到<table>

<input type="button" value="Add More" onclick="add_cust_fields()" />

table rows and cells here
<div id="extra_cust_field"></div>
rows and cells continue here

我的JScode

function add_cust_fields() {
    document.getElementById("extra_cust_field").innerHTML += 
        "<tr><td>test</td><td>test2</td></tr>";
}

我得到的只是整个桌子上方的testtest2

更改

<div id="extra_cust_field"></div>

<tbody id="extra_cust_field"></tbody>

它应该起作用。

最新更新