我有一个通过 AJAX 分页的复选框表。我正在尝试为单击这些新复选框之一创建一个单击事件。单击它时,我将需要根据该标准的 ID 更新一组 ID。
问题是,我不知道如何让我的 Javascript 在 AJAX 调用后填充输入时做出响应。如果我在视图中加载输入,则单击事件可以正常工作,但如果它通过 AJAX 返回,则无法识别。
我查看了几个类似的问题,包括:
我无法从上述任何一个问题中找到解决方案。我无法确定这里缺少什么。
HTML
<table summary="Standard Listing Table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Code</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody id="pl-standard-listing">
<tr>
<td>
<input checked="" name="standards[]" type="checkbox" value="8343">
</td>
<td>K.CC.A.1</td>
<td>Count to 100 by ones and by tens.</td>
</tr>
</tbody>
</table>
Jquery点击事件
$('#pl-standard-listing tr td').on('click', 'input[type=checkbox]', function() {
console.log("Clicked.");
console.log(this);
});
从 API 添加所有标准的输入
// Select table and whipe current standards that are listed
var table = document.getElementById('pl-standard-listing');
$('#pl-standard-listing tr').remove();
for(var iCount = 0; iCount < currentStandards.length; iCount++) {
// Check if the standard is in the list of included standards with this grade group
if(standardIds.indexOf(currentStandards[iCount].id) === -1) {
$('#pl-standard-listing').append($('<tr><td><input name="standards[]" type="checkbox" value="' + currentStandards[iCount].id + '" /></td><td>' + currentStandards[iCount].code + '</td><td>' + currentStandards[iCount].description + '</td></tr>'));
} else {
$('#pl-standard-listing').append($('<tr><td><input checked name="standards[]" type="checkbox" value="' + currentStandards[iCount].id + '" /></td><td>' + currentStandards[iCount].code + '</td><td>' + currentStandards[iCount].description + '</td></tr>'));
}
}
标准在视图中正确加载,我只是无法让事件处理程序正确地单击复选框。非常感谢任何和所有帮助。