从页面中往js里面传值
来源:互联网 发布:东三省十大网络神曲 编辑:程序博客网 时间:2024/05/14 13:02
页面中用一个hidden标签:
<c:if test="${!empty user}"> 当前用户:${user.userName} <input type="hidden" id="useractor" name="useractor" value="${user.actor}"/> </c:if>
然后在js中用这样获得:
alert($("#useractor").val());
目的是为了把用户的角色传过去,这样不同的用户可访问的内容不同,以控制它们的权限,其实完全没必要这么做,因为用户在登录成功之后,用户信息就已经保存在Session中,在各个页面之间是共享的,可以直接在页面上使用user,而无需其他地方传值.
top.jsp文件:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ include file="/pages/common/global.jsp"%><%@ taglib uri="myhellotag" prefix="user" %><%Calendar c = Calendar.getInstance();%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><%@ include file="/pages/common/jquery.jsp"%><script src="${contextPath }/js/simpleajax.js"></script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>高德软件</title><link rel="stylesheet" href="${contextPath }/css/topstyle.css" type="text/css"></link><style type="text/css"><!--body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;}.STYLE1 {font-size: 12px;color: #FFFFFF;}.STYLE2 {font-size: 9px}.STYLE3 {color: #033d61;font-size: 12px;}--></style><style>* {margin: 0 auto;padding: 0;border: 0;}body {font: 12px "宋体";color: #FFF;}.lable {background: url(${contextPath }/images/frame/top_lable.jpg) no-repeat;width: 126px;height: 28px;float: left;}.lable p {margin-top: 8px;}.menu {background: url(${contextPath }/images/frame/top_menu.jpg) no-repeat;width: 348px;height: 28px;float: right;}.menu ul {margin: 8px 0 0 45px;list-style: none;}.menu li {display: inline;}.menu a {float: left;text-decoration: none;padding-left: 2px;}.menu a:hover {text-decoration: none;}.menu a span {display: block;padding-right: 10px;color: #FFF;}.menu a:hover span {color: #004c7e;}.menu_left {background: url(${contextPath }/images/frame/menu_left.jpg) no-repeat;width: 155px;height: 22px;float: left;margin: 3px 0 0 6px;text-align: center;}.menu_left p {margin-top: 5px;}.menu_list {width: 100%;height: 25px;}.menu_list ul {margin: 0;padding: 4px 0 0 1px;list-style: none;}.menu_list li {display: inline;}.menu_list a {float: left;text-decoration: none;}.menu_list a span {display: block;padding: 4px 10px 0 10px;font: 12px "宋体" color : #004c7e;}.menu_list a:hover span {color: #FFF;border: 1px solid #004c7e;}.menu_list a:hover {background: url(${contextPath }/images/frame/menu_list.jpg) repeat-x;}</style></head><body><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="70" background="${contextPath }/images/frame/main_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="24"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="270" height="24" background="${contextPath }/images/frame/main_03.gif"> </td> <td width="505" background="${contextPath }/images/frame/main_04.gif"> </td> <td> </td> <td width="21"><img src="${contextPath }/images/frame/main_07.gif" width="21" height="24"></td> </tr> </table></td> </tr> <tr> <td height="38"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="270" height="38" background="${contextPath }/images/frame/toplogo.jpg"> </td> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="77%" height="25" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> </table></td> <td width="220" valign="bottom" nowrap="nowrap"> <div align="right"> <span class="STYLE1"> <span class="STYLE2">■</span> 今天是:<%=c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DATE)%>日星期<%=String.valueOf(c.get(Calendar.DAY_OF_WEEK)).replace("2", "一").replace("3", "二").replace("4", "三").replace("5", "四").replace("6", "五").replace("7", "六").replace("1", "日")%> </span> </div> </td> </tr> </table></td> <td width="21"><img src="${contextPath }/images/frame/main_11.gif" width="21" height="38"></td> </tr> </table></td> </tr> <tr> <td height="8" style=" line-height:8px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="270" background="${contextPath }/images/frame/main_29.gif" style=" line-height:8px;"> </td> <td width="505" background="${contextPath }/images/frame/main_30.gif" style=" line-height:8px;"> </td> <td style=" line-height:8px;"> </td> <td width="21" style=" line-height:8px;"><img src="${contextPath }/images/frame/main_31.gif" width="21" height="8"></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td height="28" background="${contextPath }/images/frame/main_36.gif"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="177" height="28" background="${contextPath }/images/frame/main_32.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="20%" height="22"> </td> <td width="59%" valign="bottom"> <div align="center" class="STYLE1"> <c:if test="${!empty user}"> 当前用户:${user.userName} <input type="hidden" id="useractor" name="useractor" value="${user.actor}"/> </c:if> </div> </td> <td width="21%"> </td> </tr> </table></td> <td background="${contextPath }/images/frame/main_36.gif"> <div id="navi" class="menu_list"> <ul> <li id="b_1"><a href="javascript:changeNavigate(1, '${contextPath }/pages/mainframe/left.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span>首页</span></a></li> <li id="b_2"><a style="font-weight:bold;" href="javascript:changeNavigate(2, '${contextPath }/pages/schedule/scheduleNavigate.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span>统计分析</span></a></li> <li id="b_3"><a href="javascript:changeNavigate(3, '${contextPath }/pages/bandwidth/bandwidthNavigate.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span>带宽信息</span></a></li> <li id="b_4"><a href="javascript:changeNavigate(4, '${contextPath }/pages/logdownload/logdownloadNavigate.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span>日志下载</span></a></li> <li id="b_5"><a href="javascript:changeNavigate(5, '${contextPath }/pages/mainframe/left.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span>在线支持</span></a></li> <li id="b_6"><a href="javascript:changeNavigate(6, '${contextPath }/pages/user/userNavigate.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span><user:myhellotag></user:myhellotag></span></a></li> <li id="b_7"><a href="javascript:changeNavigate(7, '${contextPath }/pages/mainframe/left.jsp', '${contextPath }/pages/mainframe/rightindex.jsp');"><span>帮助</span></a></li> </ul> </div> </td> <td width="50"><div align="center"><a href="javascript:logout();" ><img src="${contextPath }/images/frame/main_20.gif" width="48" height="19"></a></div></td> <td width="21"><img src="${contextPath }/images/frame/main_37.gif" width="21" height="28"></td> </tr> </table></td> </tr></table></body></html><script><!--var colorArray=new Array("#706c9c","#4f8088","#628b62","#8d668d","#806b94","#588271","#ab7a4e","#769049","#598ab6","#935c62","#8b8746");var classArray=new Array("blueadd1","cyan","green","purple","indigo","blueadd2","orange","red","blue","olivine","yellow");function heartBreak(){$.ajax({url:'${contextPath}/pages/common/heartbreak.jsp',cache:false});}setInterval('heartBreak()',10000);function index() {window.parent.location = "${contextPath }/pages/mainframe/main.jsp";}function logout() {window.parent.location = "${contextPath }/pages/j_acegi_logout";}function changeNavigate(num, leftURL, rightURL) {$('#navi > ul').children("li").removeClass();$('#navi > ul').children("li").addClass('line');var div=document.getElementById('navi');$('#b_'+(num)).addClass("blue");if(num-1>=0) {$('#b_'+(num)).prev('li').removeClass();}$('#navi').css('borderBottomColor',colorArray[num]);alert($("#useractor").val());leftURL += "?useractor=" + $("#useractor").val();window.parent.frames["mainFrame"].frames["centerFrame"].frames["leftFrame"].location = leftURL;window.parent.frames["mainFrame"].frames["centerFrame"].frames["rightFrame"].location = rightURL;}function cancelButLi(){$('#navi > ul').children("li").removeClass();$('#navi > ul').children("li").addClass('line');}function changeButLi(num,url){if(num<0)return;cancelButLi();var div=document.getElementById('navi');$('#b_'+(num)).addClass("blue");if(num-1>=0)$('#b_'+(num)).prev('li').removeClass();$('#navi').css('borderBottomColor',colorArray[num]);if(url!=null&&url!=""){window.location=url;}}try{Keeper.addListener('cometAction',refreshPage);}catch(e){}--></script>
userNavigate.jsp文件:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ include file="/pages/common/global.jsp"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><%@ include file="/pages/common/jquery.jsp"%><script src="${contextPath }/js/simpleajax.js"></script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>高德软件</title><link rel="stylesheet" href="${contextPath }/css/results.css" type="text/css" /><link rel="stylesheet" href="${contextPath }/css/style.css" type="text/css" media="all" /><link rel="stylesheet" href="${contextPath }/js/tipswindown/tipswindown.css" type="text/css" media="all" /><script src="${contextPath }/js/tipswindown/jquery.js"></script> <script src="${contextPath }/js/tipswindown/tipswindown.js"></script><script src="${contextPath }/js/simpleajax.js"></script><script type="text/javascript" src="${contextPath}/js/My97DatePicker/WdatePicker.js" defer="defer"></script><script><!--function gotoPage(currentPage,form) {goto_Page(currentPage,form,"actionDiv");}function addAccount(){$("#actionDiv").load("${contextPath }/accountAction.do?method=addAccount");$("#chance_search_div").hide();}--></script><style type="text/css"><!--body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;}.STYLE1 {font-size: 12px;color: #FFFFFF;}.STYLE3 {font-size: 12px;color: #033d61;}--></style><style type="text/css">.menu_title SPAN {FONT-WEIGHT: bold; LEFT: 3px; COLOR: #ffffff; POSITION: relative; TOP: 2px }.menu_title2 SPAN {FONT-WEIGHT: bold; LEFT: 3px; COLOR: #FFCC00; POSITION: relative; TOP: 2px}</style><script>var he=document.body.clientHeight-105document.write("<div id=tt style=height:"+he+";overflow:hidden>")</script></head><body><table width="165" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="28" background="${contextPath }/images/frame/main_40.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="19%"> </td> <td width="81%" height="20"><span class="STYLE1">管理菜单</span></td> </tr> </table></td> </tr> <tr> <td valign="top"><table width="151" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="23" background="${contextPath }/images/frame/main_47.gif" id="imgmenu1" class="menu_title" onMouseOver="this.className='menu_title2';" onClick="showsubmenu(1)" onMouseOut="this.className='menu_title';" style="cursor:hand"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="18%"> </td> <td width="82%" class="STYLE1">用户管理</td> </tr> </table></td> </tr> <tr> <td background="${contextPath }/images/frame/main_51.gif" id="submenu1"> <div class="sec_menu" > <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="16%" height="25"><div align="center"><img src="${contextPath }/images/frame/left.gif" width="10" height="10" /></div></td> <td width="84%" height="23"><table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" style="cursor:hand" onmouseover="this.style.borderStyle='solid';this.style.borderWidth='1';borderColor='#7bc4d3'; "onmouseout="this.style.borderStyle='none'" onclick="changeNavigate('${contextPath }/pages/user/userInfo.jsp');"><span class="STYLE3">用户信息</span></td> </tr> </table></td> </tr> <c:if test="${user.actor eq 3}"> <tr> <td height="23"><div align="center"><img src="${contextPath }/images/frame/left.gif" width="10" height="10" /></div></td> <td height="23"><table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" style="cursor:hand" onmouseover="this.style.borderStyle='solid';this.style.borderWidth='1';borderColor='#7bc4d3'; "onmouseout="this.style.borderStyle='none'" onclick="changeNavigate('${contextPath }/pages/user/userAdd.jsp');"><span class="STYLE3">新建用户</span></td> </tr> </table></td> </tr> </c:if> </table></td> </tr> <tr> <td height="5"><img src="${contextPath }/images/frame/main_52.gif" width="151" height="5" /></td> </tr> </table></div></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="23" background="${contextPath }/images/frame/main_47.gif" id="imgmenu2" class="menu_title" onmouseover="this.className='menu_title2';" onclick="showsubmenu(2)" onmouseout="this.className='menu_title';" style="cursor:hand"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="18%"> </td> <td width="82%" class="STYLE1">系统管理</td> </tr> </table></td> </tr> <tr> <td background="${contextPath }/images/frame/main_51.gif" id="submenu2"><div class="sec_menu" > <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="16%" height="25"><div align="center"><img src="${contextPath }/images/frame/left.gif" width="10" height="10" /></div></td> <td width="84%" height="23"><table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" style="cursor:hand" onmouseover="this.style.borderStyle='solid';this.style.borderWidth='1';borderColor='#7bc4d3'; "onmouseout="this.style.borderStyle='none'" onclick="changeNavigate('${contextPath }/pages/mainframe/construction.jsp');"><span class="STYLE3">系统配置</span></td> </tr> </table></td> </tr> <tr> <td height="23"><div align="center"><img src="${contextPath }/images/frame/left.gif" width="10" height="10" /></div></td> <td height="23"><table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" style="cursor:hand" onmouseover="this.style.borderStyle='solid';this.style.borderWidth='1';borderColor='#7bc4d3'; "onmouseout="this.style.borderStyle='none'" onclick="changeNavigate('${contextPath }/pages/mainframe/construction.jsp');"><span class="STYLE3">数据更新</span></td> </tr> </table></td> </tr> <tr> <td height="23"><div align="center"><img src="${contextPath }/images/frame/left.gif" width="10" height="10" /></div></td> <td height="23"><table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" style="cursor:hand" onmouseover="this.style.borderStyle='solid';this.style.borderWidth='1';borderColor='#7bc4d3'; "onmouseout="this.style.borderStyle='none'" onclick="changeNavigate('${contextPath }/pages/mainframe/construction.jsp');"><span class="STYLE3">网站维护</span></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td height="5"><img src="${contextPath }/images/frame/main_52.gif" width="151" height="5" /></td> </tr> </table> </div></td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> </table> </td> </tr> </table></td> </tr> <tr> <td height="18" background="${contextPath }/images/frame/main_58.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="18" valign="bottom"><div align="center" class="STYLE3">版本:2012V1.0</div></td> </tr> </table></td> </tr></table><script>function showsubmenu(sid) {whichEl = eval("submenu" + sid);imgmenu = eval("imgmenu" + sid);if(whichEl.style.display == "none") {eval("submenu" + sid + ".style.display=\"\";");imgmenu.background="${contextPath }/images/frame/main_47.gif";} else {eval("submenu" + sid + ".style.display=\"none\";");imgmenu.background="${contextPath }/images/frame/main_48.gif";}}function changeNavigate(url) {window.parent.frames["rightFrame"].location = url;}</script></body></html>
看下面这段代码:
<tr><td colspan="4" bgcolor="#FFFFFF"><div align="center"><input type="button" value="修改" class="buttonC"onclick="javascript:modifyUser('${contextPath }/userAction.do?method=toUpdateUser&userId=${user.userId }','actionDiv');"/></div></td></tr>
主要是这一句代码:
onclick="javascript:modifyUser('${contextPath }/userAction.do?method=toUpdateUser&userId=${user.userId }','actionDiv');"
是想让看一下${user.userId }的用法,直接往js里面传值。
现在看来有好多东西自己想都想不到,唉,还是要多经历!
- 从页面中往js里面传值
- jsp页面跳转中,从js里面获取url中的参数
- js 里面刷新页面
- 【JS】:JS中父页面与子页面传值
- JS 里面对页面操作
- js来获取嵌套的子页面iframe里面的html和form表单中元素值
- javascript中iframe里面的页面调用父窗口js函数的方法。
- javascript中iframe里面的页面调用父窗口js函数的方法
- 手机网页中JS倒计时在页面里面离开停滞问题
- myeclipse里面jsp页面里面js注释快捷键
- js页面传值
- JS页面传值
- js页面传值
- iframe 父页面调用子页面里面的js方法
- iframe 里面页面引用iframe 外面页面js 方法
- Js中获取超链接里面传递的参数值
- js中获取超链接参数里面的值
- Js中获取超链接里面传递的参数值
- Ubuntu 11.10 GCC4.5 GCC4.6无缝切换
- android中listView下有Button按钮始终在最底部
- Android有趣的全透明效果--Activity及Dialog的全透明(附android系统自带图标大全)
- 给右键菜单加入CMD命令行快速通道
- hydra 暴力破解工具
- 从页面中往js里面传值
- 用 Eclipse 平台进行 C/C++ 开发
- ERP实施顾问做什么?
- alter語句
- 2015年平板年销售量超过PC达5亿部
- 短距离无线通信技术全面解析
- 深入Linux设备驱动程序内核机制
- cocos2d 例子收集贴
- Java 线程池