为什么下面代码返回错误:
<script type="text/javascript">
$(document).ready(function () {
$("#chkIssueCredit").change(function () {
if (!$(this).prop('checked')) {
bootbox.confirm("Are you sure you do not want to issue a credit? Please confirm."), function (result) {
if (result) {
$(this).prop('checked', true);
}
}
return false;
//if (!confirm("Are you sure you do not want to issue a credit? Please confirm.")) {
// $(this).prop('checked', true);
//};
};
});
});
</script>
您正在关闭第一个参数之后的确认方法(消息)。在这里尝试这个:
<script type="text/javascript">
$(document).ready(function () {
$("#chkIssueCredit").change(function () {
if (!$(this).prop('checked')) {
bootbox.confirm("Are you sure you do not want to issue a credit? Please confirm.", function (result) {
if (result) {
$(this).prop('checked', true);
}
});
return false;
//if (!confirm("Are you sure you do not want to issue a credit? Please confirm.")) {
// $(this).prop('checked', true);
//};
};
});
});
</script>
您可以看到差异吗?