打开模态框,对选择框进行勾选,但不点击确定,点击取消,模态框关闭,再次打开模态框,发现之前勾选的还在,重新刷新页面,又恢复原来的状态。
以下是我的代码
图片
勾选第一个选择框
点击取消按钮,再次打开模态框,第一个勾选的应该取消掉,没有消失掉。
在网上搜了解决方法,最多的是对模态框进行监控,当模态框消失后,触发事件,清除缓存。但是下面这种解决方法没有用,另外,我也尝试了给取消添加点击事件,点击取消重新向后台发送请求,但是仍是不行。
$("#userSysAllocate").on("hidden.bs.modal", function() {
$(this).removeData("bs.modal");
});
解决方法二(不行):
创建一个bootstrap-modal-clear.js文件,引入页面中
$(function () {
// when the modal is closed
$('#modal-container').on('hidden.bs.modal', function () {
// remove the bs.modal data attribute from it
$(this).removeData('bs.modal');
// and empty the modal-content element
$('#modal-container .modal-content').empty();
});
});