此代码仅检测到更改复选框一次。在使用load()函数后,未检测到复选框中的另一个更改。Jquery在加载后未检测到复选框中的更改()
这个问题的解决方法是什么?
感谢,
的Jquery:
$(document).ready(function() {
$(".checkTask").on("change", changed);
});
function changed() {
var id = $(this).attr("idTask");
var csrftoken = getCookie('csrftoken');
// Checked
if ($(this).prop('checked')) {
$.post("/link/", {id: id, csrfmiddlewaretoken: csrftoken}, function (data) {
$("#tableTask").load(location.href + " #tableTask>*");
});
}
// Unchecked
else {
$.post("/link/", {
id: id,
csrfmiddlewaretoken: csrftoken
}, function (data) {
$("#tableTask").load(location.href + " #tableTask>*");
});
}
}
HTML:
<table class="table table-condensed table-hover table-striped">
<tbody id="tableTask">
<tr>
<td>
<input class="checkTask" type="checkbox" idTask="{{ task.id }}"/>
</td>
</tr>
</tbody>
</table>
这个复选框是否是$(“#tableTask”)'容器? –
@NikolayErmakov是的! –
实际上,你添加到你的问题的HTML说的是相反的。 –