我尝试在用户必须单击保存按钮的页面上进行安全保护。 因此,当用户单击好的部分时没有问题,但如果他进行修改并单击其他部分(导航栏),则会出现确认,表明他没有保存。
$(document).mouseup(function (e)
{
var container = $(".col-md-12");
if (!container.is(e.target) && container.has(e.target).length === 0 )
{
if (sessionStorage['Sort'])
{
var r = confirm("Disposition non sauvegardée ! Continuer ?");
}
}
});
我将 sessionStorage 用于其他函数,并在用户进行修改时填充它,目的是在“if”中使用它。
它对此工作得很好,但是如果用户单击导航栏中的某个类别,则会出现确认,如果他单击“取消”,他就会进入该类别。
这就是为什么我想在确认时禁用事件。如果他单击“取消”,用户必须留在同一页面上。 您有办法禁用所有其他事件吗?
最佳答案
您尝试过onbeforeunload吗?功能?
An event that fires when a window is about to unload its resources. The document is still visible and the event is still cancelable.
一个例子:
window.onbeforeunload = function(e) {
if (unsavedChanges) return 'Dialog text here.';
};
关于javascript - 如何暂时禁用事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679497/