[英]how to show the popup message on Exit button
我有一个这样的按钮,我该怎么办?
<input type="button" value="Exit" onclick="JavaScript:window.location.href='../index'"/>
在退出时,我要去其他视图..
单击退出时,我需要显示弹出窗口说您确定要退出吗? 带有确定和取消按钮
有人告诉我这样做吗?
谢谢
对于输入:
<input type="submit" id="exitApplication" value="Exit"/>
使用 jquery,您可以:
$("#exitApplication").click(function(){
var answer = confirm("Are you sure you want to exit?")
if(!answer){
//false when they click cancel
return false;
}
});
JavaScript:
<input type="button" value="Exit" onclick="confirmBox()" />
function confirmBox(){
if (confirm('Are you sure you want to Exit?')){
window.location.href = '../index'
}
}
jQuery:
<input type="button" value="Exit" id="exit" />
$('#exit').click(function(){
if (confirm('Are you sure you want to Exit?')){
window.location.href = '../index'
}
});
如果你有这个...
<input type="button" value="Exit" onclick="JavaScript:window.location.href='../index'"/>
...有几种方法可以实现这一点。
Chris 和 Sarfraz 解决方案都有效。 您可以做什么以及在页面的onbeforeunload
事件中添加一个confirm(...)
对话框。
<html>
<body>
Click this button to go to Google's homepage.
<input type="button" value="Exit" onclick="window.location.href='http://www.google.com'">
<script type="text/javascript">
window.onbeforeunload = function() {
return "Are you sure?";
}
</script>
</body>
</html>
这将保证,不仅当用户单击退出按钮时,而且当他/她试图离开页面时(例如,单击浏览器中的“返回”按钮。),将触发onbeforeunload
事件,并提示用户确保他/她真的想离开该页面。
如果用户说“是的,我想离开页面”,则confirm(...)
返回true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.