我有以下代码:
$("[data-toggle='toggle']").bootstrapToggle({
on: 'Active',
off: 'Inactive',
size: 'mini',
width: 100,
onstyle: 'success',
offstyle: 'danger'
});
$(document).on('change', 'input:checkbox.status-change', function(e) {
e.preventDefault();
if (confirm('Are you sure?')) {
const company_id = $(this).parent('tr').attr('id');
const status = $(this).prop('checked');
$.ajax({
url: 'customers/config/change_status.php',
method: 'POST',
data: {
companyID: company_id,
status: status
}
})
.fail(function() {
console.log("fail");
})
} else {}
})和切换(使用bootstrapToggle())
<input type="checkbox" data-toggle="toggle" class="status-change">但是,当我点击切换确认对话框弹出,甚至在点击取消后,它会改变,但ajax不会运行。但是,当我点击第二次2确认对话框将弹出相同的行为。在那之后,它只会弹出几个对话框,但都不起作用。
有人能帮上忙吗?
发布于 2020-10-11 00:21:39
所以我找到了答案。
确认对话框后添加以下内容
if (status == true) {
$(this).data('bs.toggle').on(true);
} else {
$(this).data('bs.toggle').off(true);
}github上的here中也引用了这一点
https://stackoverflow.com/questions/64294596
复制相似问题