[英]How to check and uncheck a checkbox and then create a column in the last column of the table
[英]How to create checkbox column in the table?
我正在使用以下JavaScript代碼動態創建表:
function CreatTable(data) {
var tablearea;
var table;
var thead;
var tr;
var th;
tablearea = document.getElementById('ShowDataID');
table = document.createElement('table');
thead = document.createElement('thead');
tr = document.createElement('tr');
for (var i = 0; i < data.length; i++) {
var headerTxt = document.createTextNode(data[i]);
th = document.createElement('th');
th.appendChild(headerTxt);
tr.appendChild(th);
thead.appendChild(tr);
}
table.appendChild(thead);
for (var i = 1; i < 4; i++) {
tr = document.createElement('tr');
tr.appendChild(document.createElement('td'));
tr.appendChild(document.createElement('td'));
tr.appendChild(document.createElement('td'));
tr.cells[0].appendChild(document.createTextNode('John'));
tr.cells[1].appendChild(document.createTextNode('McDowell'));
tr.cells[2].appendChild(document.createTextNode('ddd@gmail.com'));
table.appendChild(tr);
}
tablearea.appendChild(table);
}
</script>
當我創建表時,我還需要在上表中創建復選框列。
知道如何使用JavaScript實現它嗎? 還是相關的鏈接?
我不確定這是不是你問的問題:
var checkbox = document.createElement("INPUT");
checkbox.type = "checkbox";
然后你會在每一行附加checkbox
以形成一個新列。
看到這個小提琴: http : //jsfiddle.net/qeeu18g1/3/我在添加內容的地方添加了評論。
(這是這個問題的副本嗎?)
使用以下JS代碼:
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
x.setAttribute("name", "city");
x.setAttribute("value", "London");
x.setAttribute("id", 1);
並將其放置在您想要添加它的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.