點(diǎn)擊"添加"按鈕的時候如何將一段上面的代碼添加到最后新一段?我寫的是innerHTML,這種方法不支持輸出document.getElementById("tableCondensed").getElementsByTagName("tr")[1],這個問題怎么解決?
#html <table class="table-condensed" id="tableCondensed" border="0" cellpadding="2" cellspacing="0"> <thead> <tr> <th>規(guī)格名字</th> <th>規(guī)格明細(xì)</th> <th>規(guī)格價格</th> <th>庫存數(shù)量</th> <th>規(guī)格圖片</th> <th>操作方式</th> </tr> </thead> <tbody> <tr> <td> <input type="text" value="" placeholder="(比如: 顏色)"> </td> <td> <input type="text" value="" placeholder="(比如: 顏色)"> </td> <td> <input type="text" value="" placeholder="(比如: 顏色)"> </td> <td> <input type="text" value="" placeholder="(比如: 顏色)"> </td> <td> <input type="file" /> </td> <td> <ul> <li><a href="javascript:;" class="add-specitem" onclick="addSpecitem()">添加</a></li> <li><a href="javascript:;" onclick="removeSpecItem()">刪除</a></li> </ul> </td> </tr> </tbody> </table>
#javascript function addSpecitem() { var tableTh = document.getElementById("tableCondensed").getElementsByTagName("tr")[1]; var tableAddth = document.getElementById("tableCondensed"); tableAddth.innerHTML += tableTh; }