所以现在我有一个功能,只需点击一下按钮就可以在表格底部添加正确数量的单元格。
JS添加一行:
<a href="javascript:myFunction();" title="addRow" class="btn btn-info" id="row">Add Row</a>
<script>
function myFunction() {
var table = document.getElementById("data-table");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(-1);
var cell4 = row.insertCell(-1);
var cell5 = row.insertCell(-1);
var cell6 = row.insertCell(-1);
cell1.innerHTML = "Video File Name";
cell2.innerHTML = "Original File Size";
cell3.innerHTML = "23432";
cell4.innerHTML = "23423";
cell5.innerHTML = "2342";
cell6.innerHTML = "Compress";
}
当我点击添加行按钮时,如何在第6个单元格中添加按钮?
答案 0 :(得分:4)
在设置innerHTML
属性时,只需更改第六个单元格的内容(即cell6
)以明确包含按钮:
// This sets the HTML within your cell, so include whatever you need within it
cell6.innerHTML = "<button>Compress</button>";