layui给元素绑定事件:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>layer-更懂你的web弹窗解决方案</title> <style> html{background-color:#E3E3E3; font-size:14px; color:#000; font-family:'微软雅黑'} a,a:hover{ text-decoration:none;} pre{font-family:'微软雅黑'} .box{padding:20px; background-color:#fff; margin:50px 100px; border-radius:5px;} .box a{padding-right:15px;} #about_hide{display:none} .layer_text{background-color:#fff; padding:20px;} .layer_text p{margin-bottom: 10px; text-indent: 2em; line-height: 23px;} .button{display:inline-block; *display:inline; *zoom:1; line-height:30px; padding:0 20px; background-color:#56B4DC; color:#fff; font-size:14px; border-radius:3px; cursor:pointer; font-weight:normal;} .photos-demo img{width:200px;} </style> <script src="jquery-1.8.3.min.js"></script> <script src="../layer-v3.1.1/layer/layer.js"></script> </head> <script> function panduan2(id) { var num=document.getElementById("a").value; if(num==0){ layer.confirm('你还未登录,无法进行操作,请先去登录', {icon: 5, title:'提示'}, function(index){ window.location.href="index2.jsp";//还未登录跳转到登录页面 layer.close(index); }); } else { window.location.href=("contact2.jsp?place="+id);//登录成功后需要跳转的页面加参数 } } </script> <body> <% String loginname=""; int a=0; if(session.getAttribute("username")==null){ loginname="error"; }else { loginname=(String)session.getAttribute("username"); a=1; } %> <input type="hidden" id="a" value="<%=a%>"> <div class="box" style="text-align:center"> <a onclick="panduan2('oo')" id="about">验证</a> </div> </body> </html>