[英]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.