弹窗
提示警告:
alert("禁止");
提示是否退出,或者执行某个操作(跳转,删除等):
confirm(“是否退出”);
跳转
当使用a标签触发js函数时
a标签的href跳转会在window.location.href之前执行
导致window.location.href无效
同理,当a标签在form表单时,表单的提交也会在window.location.href之前执行
也会导致window.location.href无效
解决方法:
将 οnclick="logout()" 改为 οnclick="logout()"
并在js函数中加上 return false;
这样能使window.location.href顺利跳转
代码如下:
<a href="" onclick="return logout()" >退出登录</a>
<script type="text/javascript">
function logout(){
var choose = confirm("确定要退出吗?");
if(choose==true){
window.location.href="<%=path%>/servlet/LogoutManagerServlet";
return false;
}
}
<script>
点击确认,跳转到servlet后执行注销用户操作