我试图突出显示链接到新页面的所选菜单项。将背景图像交换为较亮的图像是可行的,但该设置在页面上滞后。索引页是正确的,但随后它开始突出显示先前单击的菜单项。
request.setAttribute("menuitem","home")
我开始在每个页面上使用 JSP ( ) 的会话属性。页面由两部分组成:
- 标题
- 身体
菜单位于标题中,单击菜单项会重新加载整个页面。添加setAttribute
是通过每个页面正文顶部的脚本进行的。页面加载完成后,我将类更改为突出显示。
我该如何解决这种对突出变化的迟到反应?? 还是我应该使用不同的方法? 菜单项示例:
<div id="home" class="menu clickable"
<div>Home</div>
</div>
剧本:
<script>
function checkMenuItem() {
/*var selected=getMenuItem("selectedmenu");*/
var selected = <%= (String) request.getAttribute("selectedmenu") %>
if (selected != null && selected != "") {
switch (selected) {
case 'home':
$("#home").removeClass('clickable').addClass('selected');
$(".menu").not("#home").addClass('clickable'); <% chosenpage = "home";
request.setAttribute("selectedmenu", chosenpage); %>
break;
case 'upload':
$("#upload").removeClass('clickable').addClass('selected');
$(".menu").not("#upload").addClass('clickable'); <% chosenpage = "upload";
request.setAttribute("selectedmenu", chosenpage); %>
break;
case 'question':
$("#question").removeClass('clickable').addClass('selected');
$(".menu").not("#question").addClass('clickable'); <% chosenpage = "question";
request.setAttribute("selectedmenu", chosenpage); %>
break;
case 'plan':
$("#plan").removeClass('clickable').addClass('selected');
$(".menu").not("#plan").addClass('clickable'); <% chosenpage = "plan";
request.setAttribute("selectedmenu", chosenpage); %>
break;
case 'indication':
$("#indication").removeClass('clickable').addClass('selected');
$(".menu").not("#indication").addClass('clickable'); <% chosenpage = "indication";
request.setAttribute("selectedmenu", chosenpage); %>
break;
default: $("#home").removeClass('clickable').addClass('selected');
$(".menu").not("#home").addClass('clickable');
break;
}
} //end if
}
$('document').ready(function () {
checkMenuItem();
$("#home").click(
function(){ document.location.href="<%=request.getContextPath()%>/index.html";} );
$("#upload").click(
function(){ document.location.href="<%=request.getContextPath()%>/upload.html";} );
$("#indicator").click(
function(){ document.location.href="<%=request.getContextPath()%>/plan/indicator.html";} );
$("#plan").click(
function(){ document.location.href="<%=request.getContextPath()%>/plan/improvementplans.html";} );
$("#question").click(
function(){ document.location.href="<%=request.getContextPath()%>/question.html";} );
});
</script>