此代碼僅檢測到更改複選框一次。在使用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說的是相反的。 –