我有一个包含文本框和提交按钮的网页。当用户编辑文本框中的文本并单击另一个链接(不是提交按钮)时,我如何显示“您确定要离开此页面”弹出消息吗?
我在网上对此进行了研究,并找到了一些 javascript 示例。这是你能做到这一点的唯一方法吗?如果不是,最好的方法是什么?
最佳答案
这是实现同一件事的多种方法之一
function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload=goodbye;
从这里得到 open js
关于c# - 如何在浏览器中生成 'Are you sure you want to navigate away from this page' 警告消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9395515/