JSP中JS弹出未登录提示框并自动跳转

JavaScript014

JSP中JS弹出未登录提示框并自动跳转,第1张

给你写个例子

<%

String username = (String) session.getAttribute("sUser")

if(username!=null)//如果这个不等于空,那么证明已经登录

{

MessageBiz bmb = new MessageBizImpl()

List<Message>list = bmb.findMessages(username)

request.setAttribute("msgs", list)

}else

{

%>

<script type="text/javascript">alert("请先登陆")window.location="../login.jsp" </script>

<%

//如果session 为空那么证明没有登录将跳到login.jsp

}

%>

鼠标点击事件就是当鼠标点击元素时,就会出现另一个窗口。

首页中右上角的登录这个按钮,当鼠标点击登录时,就会出现登录窗口。

如果直接用javascript来修改css效果的话会非常麻烦,可以用click方法来实现鼠标点击事件。

用摸态框(以下示例代码来自:菜鸟教程)。

<!DOCTYPE html>

<html>

<head>

<title>Foundation 实例</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/foundation/5.5.3/css/foundation.min.css">

<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="http://cdn.static.runoob.com/libs/foundation/5.5.3/js/foundation.min.js"></script>

<script src="http://cdn.static.runoob.com/libs/foundation/5.5.3/js/vendor/modernizr.js"></script>

</head>

<body style="padding:20px">

<div style="padding:20px">

<h2>模态框</h2>

<p>模态框是一个显示在页面头部的弹窗。</p>

<button type="button" class="button" data-reveal-id="myModal">点我打开模态框</button>

<div id="myModal" class="reveal-modal" data-reveal>

<h2>Heading in Modal.</h2>

<p>Some text in the modal.</p>

<p>Some text in the modal.</p>

<a class="close-reveal-modal">×</a>

</div>

</div>

<script>

$(document).ready(function() {

$(document).foundation()

})

</script>

</body>

</html>