确认消息返回错误 [英] Confirm message returns error
本文介绍了确认消息返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一条确认消息,其中包含两个确定按钮,然后取消以关闭页面....
当我单击确定"时,页面需要关闭,然后单击取消",页面将保持不变...
但是在我的编码中,取消"按钮单击该页面即可关闭....
我知道我的编码有错误...但是我无法到达错误所在的地方...
我的代码在这里...
I have one confirm message which contain two button ok and cancel for closing the page ....
When I click OK the page need to close and clicking the cancel the page will stay...
But in my coding the cancel button clicks the page get close....
I know my coding is in error...But I cant get where the error is......
my code is here...
if (!isClose) {
var agree;
agree = confirm('Are you sure to close the window');
if (agree) {
return true;
}
else {
return false;
}
}
谁能帮助我....
Can anyone help me....
推荐答案
您需要使用beforeunload
事件.这个问题的答案显示了如何使用jQuery:
http://www.mkyong.com /jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/ [
You need to usebeforeunload
event. The answer to this question shows how to do it with jQuery:
http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/[^].
Please see the source code and run demo page to see how it works.
—SA
用以下代码替换您的代码:
replace your code with the following:
if (!isClose) {
if (confirm('Are you sure to close the window?')) {
//close code here
return true;
} else {
return false;
}
}
希望这会帮助你.祝你好运.
hope this will help you. good luck.
这篇关于确认消息返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文