js脚本实现树形菜单
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}
function writeCookie(name, value, hours)
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">求职意向</a></td></tr>
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">上传照片</a></td></tr>
var found = false;
for(i=0;i<arr_curShow.length-1;i++)
{
if(arr_curShow[i].toString()==id) {found=true;}
}
if(!found){writeCookie('curShow',curShow+','+id,12)}
</tbody>
<tbody id="c_1" style="display: none">
<tr>
<td class="leftmenu2"><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="http://www.baidu.com">基本信息</a></td></tr>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>刷新不变化树形菜单- js树形菜单_树形菜单代码</title>
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if(curShow!='')
{
var arr_curShow = curShow.split(',');
for(i=0;i<arr_curShow.length;i++)
{
if(arr_curShow[i].toString()==id) {arr_curShow=arr_curShow.del(i--);}
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">简历预览</a></td></tr>
</tbody>
<tbody>
用脚本语言实现树形菜单
在网页中,用js脚本实现的树形菜单:
可以新建html直接运行.方便自己查看
<!--Modify by visc.cn for cbiw.com.cn 2007-03-19-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style type="text/css">
body,td,th {font-size: 14px;}
.leftmenu1 {font-weight: bold; cursor: hand; padding-top: 4px; height: 29px; text-align: left;}
.leftmenu2 {PADDING-LEFT:15px; height: 21px;text-align: left;}
<tr>
<td class="leftmenu2"><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="http://www.baidu.com">修改密码</a></td></tr>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(3,img3)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img3"/><span class="ft_white">职位搜索</span></a></td></tr>
}
Array.prototype.del=function(n) { //n表示第几项,从0开始算起。
//prototype为对象原型,注意这里为对象增加自定义方法的方法。
if(n<0) //如果n<0,则不进行任何操作。
return this;
else
return this.slice(0,n).concat(this.slice(n+1,this.length));
}
window.onload = function a()
{
var curShow = readCookie('curShow');
var totalShow = 5; //自己修改一共有多少个二级分类
if(curShow!=''&&curShow!=null)
{
for(i=1;i<=totalShow;i++)
div{ margin-top:90px; width:100%; text-align:center; }
</style>
</head>
<body>
<div>
<script language="JavaScript" type="text/javascript">
function Show(id,i_id){
{
document.getElementById('c_'+i).display="none";
}
var arr_curShow;
arr_curShow = curShow.split(',');
for(i=0;i<=arr_curShow.length-1;i++)
{
if(arr_curShow[i]!=''){document.getElementById('c_'+arr_curShow[i]).style.display="";}
}
else {
writeCookie('curShow',id,12)
}
//将子菜单Id放入Cookies End
}else{
obj.style.display="none";
iwenku.baidu.comid.src=off_img;
//将子菜单Id从Cookies中移除
var curShow = readCookie('curShow');
var on_img="http://www.cbiw.com.cn/member/pic/ass04.gif";//打开时图片
var off_img="http://www.cbiw.com.cn/member/pic/ass03.gif";//隐藏时图片
var obj=document.getElementById('c_'+id);
</tbody>
<tbody id="c_3" style="display: none">
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">快速搜索</a></td></tr>
</tbody>
<tbody id="c_2" style="display: none">
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">求职简历</a></td></tr>
if(obj.style.display=="none"){
obj.style.display="";
i_id.src=on_img;
//将子菜单Id放入Cookies
var curShow = readCookie('curShow');
if(curShow!='')
{
var arr_curShow = curShow.split(',');
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
</tbody>
<tbody>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(4,img4)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img4"/><span class="ft_white">应聘管理</span></a></td></tr>
}
}
}
</script>
<table width="10%" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(1,img1)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img1"/><span class="ft_white">个人资料</span></a></td></tr>
}
curShow = arr_curShow.join(',');
//alert(curShow);
writeCookie('curShow',curShow,12)
}
//将子菜单Id从Cookies中移除End
}
}
function readCookie(name)
{
var cookieValue = "";
</tbody>
<tbody>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(2,img2)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img2"/><span class="ft_white">我的简历</span></a></td></tr>
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue;
}
function writeCookie(name, value, hours)
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">求职意向</a></td></tr>
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">上传照片</a></td></tr>
var found = false;
for(i=0;i<arr_curShow.length-1;i++)
{
if(arr_curShow[i].toString()==id) {found=true;}
}
if(!found){writeCookie('curShow',curShow+','+id,12)}
</tbody>
<tbody id="c_1" style="display: none">
<tr>
<td class="leftmenu2"><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="http://www.baidu.com">基本信息</a></td></tr>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>刷新不变化树形菜单- js树形菜单_树形菜单代码</title>
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if(curShow!='')
{
var arr_curShow = curShow.split(',');
for(i=0;i<arr_curShow.length;i++)
{
if(arr_curShow[i].toString()==id) {arr_curShow=arr_curShow.del(i--);}
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">简历预览</a></td></tr>
</tbody>
<tbody>
用脚本语言实现树形菜单
在网页中,用js脚本实现的树形菜单:
可以新建html直接运行.方便自己查看
<!--Modify by visc.cn for cbiw.com.cn 2007-03-19-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style type="text/css">
body,td,th {font-size: 14px;}
.leftmenu1 {font-weight: bold; cursor: hand; padding-top: 4px; height: 29px; text-align: left;}
.leftmenu2 {PADDING-LEFT:15px; height: 21px;text-align: left;}
<tr>
<td class="leftmenu2"><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="http://www.baidu.com">修改密码</a></td></tr>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(3,img3)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img3"/><span class="ft_white">职位搜索</span></a></td></tr>
}
Array.prototype.del=function(n) { //n表示第几项,从0开始算起。
//prototype为对象原型,注意这里为对象增加自定义方法的方法。
if(n<0) //如果n<0,则不进行任何操作。
return this;
else
return this.slice(0,n).concat(this.slice(n+1,this.length));
}
window.onload = function a()
{
var curShow = readCookie('curShow');
var totalShow = 5; //自己修改一共有多少个二级分类
if(curShow!=''&&curShow!=null)
{
for(i=1;i<=totalShow;i++)
div{ margin-top:90px; width:100%; text-align:center; }
</style>
</head>
<body>
<div>
<script language="JavaScript" type="text/javascript">
function Show(id,i_id){
{
document.getElementById('c_'+i).display="none";
}
var arr_curShow;
arr_curShow = curShow.split(',');
for(i=0;i<=arr_curShow.length-1;i++)
{
if(arr_curShow[i]!=''){document.getElementById('c_'+arr_curShow[i]).style.display="";}
}
else {
writeCookie('curShow',id,12)
}
//将子菜单Id放入Cookies End
}else{
obj.style.display="none";
iwenku.baidu.comid.src=off_img;
//将子菜单Id从Cookies中移除
var curShow = readCookie('curShow');
var on_img="http://www.cbiw.com.cn/member/pic/ass04.gif";//打开时图片
var off_img="http://www.cbiw.com.cn/member/pic/ass03.gif";//隐藏时图片
var obj=document.getElementById('c_'+id);
</tbody>
<tbody id="c_3" style="display: none">
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">快速搜索</a></td></tr>
</tbody>
<tbody id="c_2" style="display: none">
<tr>
<td class="leftmenu2" ><img src="http://www.cbiw.com.cn/member/pic/ass06.gif" width="9" height="9" /> <a href="#">求职简历</a></td></tr>
if(obj.style.display=="none"){
obj.style.display="";
i_id.src=on_img;
//将子菜单Id放入Cookies
var curShow = readCookie('curShow');
if(curShow!='')
{
var arr_curShow = curShow.split(',');
{
var expire = "";
if(hours != null)
{
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire;
</tbody>
<tbody>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(4,img4)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img4"/><span class="ft_white">应聘管理</span></a></td></tr>
}
}
}
</script>
<table width="10%" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(1,img1)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img1"/><span class="ft_white">个人资料</span></a></td></tr>
}
curShow = arr_curShow.join(',');
//alert(curShow);
writeCookie('curShow',curShow,12)
}
//将子菜单Id从Cookies中移除End
}
}
function readCookie(name)
{
var cookieValue = "";
</tbody>
<tbody>
<tr>
<td class="leftmenu1"> <a style="cursor: pointer" onclick="Show(2,img2)"><img src="http://www.cbiw.com.cn/member/pic/ass03.gif" width="16" height="16" align="absmiddle" id="img2"/><span class="ft_white">我的简历</span></a></td></tr>