我使用 Java 脚本动态地将多个复选框(使用“for”循环,在代码部分中省略,以便于理解)添加到 html 表格的每一行中。代码是这样的,
var table = document.getElementById("verifyTable");
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
cell1.innerHTML = "<input type='checkbox' class = 'checkSensors' id='checkSensorsId' value=''>";
然后在运行时,当选中/取消选中复选框时,将使用 JQuery 触发事件,如下所示,
$(document).on('change', '[type=checkbox]', function() {
$("table tr td:nth-child(1)").each(function () {
var checkbox = $(this).html();
alert(checkbox);
});
});
不幸的是,内部 html 文本 <input type='checkbox' class = 'checkSensors' id='checkSensorsId' value=''>
是我收到的输出。我无法找出如何获取 insidehtml“输入”元素的值的方法。请帮我解决这个问题。
最佳答案
根据评论中的建议对 for 选择器进行了一些更改并使其正常工作。
$(document).on('change', '[type=checkbox]', function() {
$("table tr td:nth-child(1) input").each(function() {
alert($(this).is(":checked"));
});
});
关于javascript - 如何读取作为内部 html 动态插入到表格单元格中的 html 表格内的复选框的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574773/