DDR爱好者之家 Design By 杰米
在网上找个很多的树实现,总感觉不尽如意,不是需要引用JS外部文件使用插件,就是代码过多让人看的眼花,实际上我只是想实现一个代码简洁、逻辑不复杂的树,费话不多说直接上代码:
1,首先写CSS样式,这个必需要写的头部最先渲染
复制代码 代码如下:
<style>
.ps{margin-left:10px;display:none;}
.f {
background: url("add.gif") no-repeat scroll -4px -21px;
cursor: pointer;
height: 35px;
line-height: 37px;
padding-left: 20px;
}
</style>
2,在页面主体中添加树的具体内容,此内容也可以动态展示(动态展示只要针对规则就很好实现了,这就不用说了吧偷笑)
复制代码 代码如下:
<div class="f" id="sgc1">密码修改</div>
<div class="f" id="sgc2">商品选择</div>
<div class="f" id="sgc3" onclick="w('gc3')">分类设置</div>
<div class="ps" id="gc3" style="display:none">
<div id="sfgc91" class="f" onclick="k('fgc91')">Must See</div>
<div class="ps" id="fgc91">
<div class="f">设置MustSee商品</div>
</div>
<div id="sfgc93" class="f" onclick="k('fgc93')">Spotlight</div>
<div class="ps" id="fgc93">
<div class="f">设置Spotlight商品</div>
</div>
<div id="sfgc94" class="f" onclick="k('fgc94')">Daily Specials</div>
<div class="ps" id="fgc94">
<div class="f">设置DailySpecials商品</div>
</div>
<div id="sfgc95" class="f" onclick="k('fgc95')">HotCategory</div>
<div class="ps" id="fgc95">
<div class="f">设置HotCategory分类</div>
<div class="f">设置HotCategory商品</div>
</div>
<div id="sfgc96" class="f" onclick="k('fgc96')">Hot & Cool Picks</div>
<div class="ps" id="fgc96">
<div class="f">设置Hot & Cool Picks商品</div>
</div>
<div id="sfgc97" class="f" onclick="k('fgc97')">FeaturedCategorie</div>
<div class="ps" id="fgc97">
<div class="f">设置FeaturedCategorie分类</div>
<div class="f">设置FeaturedCategorie商品</div>
</div>
<div id="sfgc98" class="f" onclick="k('fgc98')">You Might Also Like…</div>
<div class="ps" id="fgc98">
<div class="f">设置You Might Also Like…分类</div>
<div class="f">设置You Might Also Like…商品</div>
</div>
</div>
<div class="f" id="sgc4" onclick="w('gc4')">系统设置</div>
<div class="ps" id="gc4" style="display:none">
<div class="f">用户管理</div>
</div>
3,重头戏来了,同鞋注意了,接下来实现JS的树形控制
复制代码 代码如下:
function w(vd) {
var ob = document.getElementById(vd);
if (ob.style.display == "block" || ob.style.display == "") {
ob.style.display = "none";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px -21px no-repeat";
}
else {
ob.style.display = "block";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px 4px no-repeat;";
}
}
function k(vd) {
var ob = document.getElementById(vd);
if (ob.style.display == "block") {
ob.style.display = "none";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px -21px no-repeat";
}
else {
ob.style.display = "block";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px 4px no-repeat;";
}
}
4,运行实例图如下:
1,首先写CSS样式,这个必需要写的头部最先渲染
复制代码 代码如下:
<style>
.ps{margin-left:10px;display:none;}
.f {
background: url("add.gif") no-repeat scroll -4px -21px;
cursor: pointer;
height: 35px;
line-height: 37px;
padding-left: 20px;
}
</style>
2,在页面主体中添加树的具体内容,此内容也可以动态展示(动态展示只要针对规则就很好实现了,这就不用说了吧偷笑)
复制代码 代码如下:
<div class="f" id="sgc1">密码修改</div>
<div class="f" id="sgc2">商品选择</div>
<div class="f" id="sgc3" onclick="w('gc3')">分类设置</div>
<div class="ps" id="gc3" style="display:none">
<div id="sfgc91" class="f" onclick="k('fgc91')">Must See</div>
<div class="ps" id="fgc91">
<div class="f">设置MustSee商品</div>
</div>
<div id="sfgc93" class="f" onclick="k('fgc93')">Spotlight</div>
<div class="ps" id="fgc93">
<div class="f">设置Spotlight商品</div>
</div>
<div id="sfgc94" class="f" onclick="k('fgc94')">Daily Specials</div>
<div class="ps" id="fgc94">
<div class="f">设置DailySpecials商品</div>
</div>
<div id="sfgc95" class="f" onclick="k('fgc95')">HotCategory</div>
<div class="ps" id="fgc95">
<div class="f">设置HotCategory分类</div>
<div class="f">设置HotCategory商品</div>
</div>
<div id="sfgc96" class="f" onclick="k('fgc96')">Hot & Cool Picks</div>
<div class="ps" id="fgc96">
<div class="f">设置Hot & Cool Picks商品</div>
</div>
<div id="sfgc97" class="f" onclick="k('fgc97')">FeaturedCategorie</div>
<div class="ps" id="fgc97">
<div class="f">设置FeaturedCategorie分类</div>
<div class="f">设置FeaturedCategorie商品</div>
</div>
<div id="sfgc98" class="f" onclick="k('fgc98')">You Might Also Like…</div>
<div class="ps" id="fgc98">
<div class="f">设置You Might Also Like…分类</div>
<div class="f">设置You Might Also Like…商品</div>
</div>
</div>
<div class="f" id="sgc4" onclick="w('gc4')">系统设置</div>
<div class="ps" id="gc4" style="display:none">
<div class="f">用户管理</div>
</div>
3,重头戏来了,同鞋注意了,接下来实现JS的树形控制
复制代码 代码如下:
function w(vd) {
var ob = document.getElementById(vd);
if (ob.style.display == "block" || ob.style.display == "") {
ob.style.display = "none";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px -21px no-repeat";
}
else {
ob.style.display = "block";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px 4px no-repeat;";
}
}
function k(vd) {
var ob = document.getElementById(vd);
if (ob.style.display == "block") {
ob.style.display = "none";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px -21px no-repeat";
}
else {
ob.style.display = "block";
var ob2 = document.getElementById('s' + vd);
ob2.style.background = "url(add.gif) -4px 4px no-repeat;";
}
}
4,运行实例图如下:
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2025年01月20日
2025年01月20日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]