![]() |
#2
foktime2010-08-11 16:38
用cookie保存状态
另外你的js部分写的太罗嗦了,给你改了一下 html部分也改了,没有说点击这种导航切换效果还要打开新页面的 ![]() <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript"> function $(id) { return document.getElementById(id); } function showleftmenu(num){ for (var i = 0; i < 3; i++) { $("help_center_leftmenu" + i).className = ""; $("menu_content" + i).style.display = "none"; } $("help_center_leftmenu" + num).className = "active"; $("menu_content" + num).style.display = "block"; SetCookie("flag", num); } function initfn() { if (getCookie('flag')) { var n = getCookie('flag'); for (var i = 0; i < 3; i++) { $("help_center_leftmenu" + i).className = ""; $("menu_content" + i).style.display = "none"; } $("help_center_leftmenu" + n).className = "active"; $("menu_content" + n).style.display = "block"; } } function showmenuitem(thisid){ var items=document.getElementById("help_categories").getElementsByTagName("a"); for(var i=0;i<items.length;i++){ if(items[i].className=="style"){ items[i].className=""; } } thisid.className="style"; } //写cookies函数 function SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值 { var Days = 30; //此 cookie 将被保存 30 天 var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } function getCookie(name)//取cookies函数 { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return unescape(arr[2]); return null; } function delCookie(name)//删除cookie { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString(); } </script> <style type="text/css"> #help_categories { width:157px; height:468px; background:#eff0f2; margin:4px 0 0 4px; } .classification { width:157px; float:left; height:auto; } .set_up { width:157px; float:left; height:auto; } .set_up h3 { text-align:center; background:#d2d8e4; height:auto; line-height:30px; font-size:12px; font-weight:bold; cursor:pointer; } .set_up h3.active { background:#e95412; height:auto; line-height:47px; color:#FFF; } .set_up h3 a, .set_up a { color:#000000; display:block; } .set_up ul li { width:150px; float:right; line-height:25px; } </style> </head> <body onload="initfn()"> <div id="help_categories"> <div class="classification"> <div class="set_up"> <h3 id="help_center_leftmenu1"><a style="cursor:hand" onmousedown="showleftmenu(1)">项目浏览</a></h3> <ul id="menu_content1" style="display:none;"> </ul> </div> <div class="set_up" style="margin-top:3px;"> <h3 id="help_center_leftmenu2"><a style="cursor:hand" onmousedown="showleftmenu(2)">查询项目</a></h3> <ul id="menu_content2" style="display:none;"> </ul> </div> <div class="set_up" style="margin-top:3px;"> <h3 id="help_center_leftmenu0" class="active"><a style="cursor:hand" onmousedown="showleftmenu(0)">项目汇总</a></h3> <ul id="menu_content0"> <li><a onclick="showmenuitem(this)" style=" cursor:pointer" >·标志设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·VI设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·包装设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·网站设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·空间设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·导示设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·工业设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·品牌顾问</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·品牌命名</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·广告设计</a></li> <li><a onclick="showmenuitem(this)" style=" cursor:pointer">·传媒设计</a></li> </ul> </div> </div> </div> </body> </html> 运行下试试 [ 本帖最后由 foktime 于 2010-8-11 16:51 编辑 ] |
比如:我选择了第二个一级导航“查询项目”; 我刷新页面后还是在“查询项目”,不会跳到“项目汇总”;总导航点击背景色会变得那种。
在线等了,高手急救!!!急急急。。。。由于后台不会做局部刷新。
只有本站会员才能查看附件,请 登录

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function showleftmenu(num){
if(document.getElementById("help_center_leftmenu"+num).className=="active"){
for(var i=0;i<3;i++){
document.getElementById("help_center_leftmenu"+i).className="";
document.getElementById("menu_content"+i).style.display="none";
}
}else{
for(var i=0;i<3;i++){
document.getElementById("help_center_leftmenu"+i).className="";
document.getElementById("menu_content"+i).style.display="none";
}
document.getElementById("help_center_leftmenu"+num).className="active";
document.getElementById("menu_content"+num).style.display="block";
}
}
function showmenuitem(thisid){
var items=document.getElementById("help_categories").getElementsByTagName("a");
for(var i=0;i<items.length;i++){
if(items[i].className=="style"){
items[i].className="";
}
}
thisid.className="style";
}
</script>
<style type="text/css">
#help_categories {
width:157px;
height:468px;
background:#eff0f2;
margin:4px 0 0 4px;
}
.classification {
width:157px;
float:left;
height:auto;
}
.set_up {
width:157px;
float:left;
height:auto;
}
.set_up h3 {
text-align:center;
background:#330000;
height:auto;
line-height:30px;
font-size:12px;
font-weight:bold;
cursor:pointer;
}
.set_up h3.active {
background:#006600;
height:auto;
line-height:47px;
color:#FFF;
}
.set_up h3 a, .set_up a {
color:#000000;
display:block;
}
.set_up ul li {
width:150px;
float:right;
line-height:25px;
}
</style>
</head>
<body>
<div id="help_categories">
<div class="classification">
<div class="set_up">
<h3 id="help_center_leftmenu1"><a href="#" onmousedown="showleftmenu(1)" target="_blank">项目浏览</a></h3>
<ul id="menu_content1" style="display:none;">
</ul>
</div>
<div class="set_up" style="margin-top:3px;">
<h3 id="help_center_leftmenu2"><a href="#" onmousedown="showleftmenu(2)" target="_blank">查询项目</a></h3>
<ul id="menu_content2" style="display:none;">
</ul>
</div>
<div class="set_up" style="margin-top:3px;">
<h3 id="help_center_leftmenu0" class="active"><a href="#" onmousedown="showleftmenu(0)">项目汇总</a></h3>
<ul id="menu_content0">
<li><a onclick="showmenuitem(this)" style=" cursor:pointer" >·标志设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·VI设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·包装设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·网站设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·空间设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·导示设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·工业设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·品牌顾问</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·品牌命名</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·广告设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·传媒设计</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
<title>无标题文档</title>
<script language="javascript">
function showleftmenu(num){
if(document.getElementById("help_center_leftmenu"+num).className=="active"){
for(var i=0;i<3;i++){
document.getElementById("help_center_leftmenu"+i).className="";
document.getElementById("menu_content"+i).style.display="none";
}
}else{
for(var i=0;i<3;i++){
document.getElementById("help_center_leftmenu"+i).className="";
document.getElementById("menu_content"+i).style.display="none";
}
document.getElementById("help_center_leftmenu"+num).className="active";
document.getElementById("menu_content"+num).style.display="block";
}
}
function showmenuitem(thisid){
var items=document.getElementById("help_categories").getElementsByTagName("a");
for(var i=0;i<items.length;i++){
if(items[i].className=="style"){
items[i].className="";
}
}
thisid.className="style";
}
</script>
<style type="text/css">
#help_categories {
width:157px;
height:468px;
background:#eff0f2;
margin:4px 0 0 4px;
}
.classification {
width:157px;
float:left;
height:auto;
}
.set_up {
width:157px;
float:left;
height:auto;
}
.set_up h3 {
text-align:center;
background:#330000;
height:auto;
line-height:30px;
font-size:12px;
font-weight:bold;
cursor:pointer;
}
.set_up h3.active {
background:#006600;
height:auto;
line-height:47px;
color:#FFF;
}
.set_up h3 a, .set_up a {
color:#000000;
display:block;
}
.set_up ul li {
width:150px;
float:right;
line-height:25px;
}
</style>
</head>
<body>
<div id="help_categories">
<div class="classification">
<div class="set_up">
<h3 id="help_center_leftmenu1"><a href="#" onmousedown="showleftmenu(1)" target="_blank">项目浏览</a></h3>
<ul id="menu_content1" style="display:none;">
</ul>
</div>
<div class="set_up" style="margin-top:3px;">
<h3 id="help_center_leftmenu2"><a href="#" onmousedown="showleftmenu(2)" target="_blank">查询项目</a></h3>
<ul id="menu_content2" style="display:none;">
</ul>
</div>
<div class="set_up" style="margin-top:3px;">
<h3 id="help_center_leftmenu0" class="active"><a href="#" onmousedown="showleftmenu(0)">项目汇总</a></h3>
<ul id="menu_content0">
<li><a onclick="showmenuitem(this)" style=" cursor:pointer" >·标志设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·VI设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·包装设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·网站设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·空间设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·导示设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·工业设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·品牌顾问</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·品牌命名</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·广告设计</a></li>
<li><a onclick="showmenuitem(this)" style=" cursor:pointer">·传媒设计</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
[ 本帖最后由 liweilkm 于 2010-8-11 16:11 编辑 ]