我想在选项卡关闭时显示“onbeforeunload
警报”,但是当我填写表单然后关闭选项卡时,“onbeforeunload
警报”不会出现。
如何更改代码,以便在填写表单时显示“onbeforeunload
警报”?
这是我使用的代码:
window.onbeforeunload = confirmExit;
function confirmExit() {
return "You are about to exit the system before freezing your declaration! If you leave now and never return to freeze your declaration; then they will not go into effect and you may lose tax deduction, Are you sure you want to leave now?";
}
$(function() {
$("a").click(function() {
window.onbeforeunload = null;
});
$("input").click(function() {
window.onbeforeunload = null;
});
});
最佳答案
How can I change the code so "
unbeforeunload
alert" can show when the form is filled?
您实际上点击的是<input />
通过填写表格吗?因此,一旦您单击 <input />
,unbeforeunload
设置为 null
(删除警报)通过以下代码:
$("input").click(function() {
window.onbeforeunload = null;
});
请删除该代码,然后就一切就绪了。 :)
或者您可以定位提交按钮,更具体地说:
$("input").click(function() {
window.onbeforeunload = null;
});
$("input[type='submit']").click(function() {
window.onbeforeunload = confirmExit;
});
关于javascript - 如何在填写表单时显示 onbeforeunload 警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625529/