写了一个html树形结构但是怎么才可以让他打开html页面的时候显示的是只有两个节点

zhangyikai321 2015-11-30 01:40:18
代码贴出来了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery实现多级树形分类可折叠菜单特效代码</title>

<!--图标样式-->
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />

<!--主要样式-->
<link rel="stylesheet" type="text/css" href="css/style.css" />



</head>
<body>

<div class="tree well">
<ul>
<li>
<span><i class="icon-folder-open"></i> Parent</span> <a href="">Goes somewhere</a>
<ul>
<li>
<span><i class="icon-minus-sign"></i> Child</span> <a href="">Goes somewhere</a>
<ul>
<li>
<span><i class="icon-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a>
</li>
</ul>
</li>
<li>
<span><i class="icon-minus-sign"></i> Child</span> <a href="">Goes somewhere</a>
<ul>
<li>
<span><i class="icon-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a>
</li>
<li>
<span><i class="icon-minus-sign"></i> Grand Child</span> <a href="">Goes somewhere</a>
<ul>
<li>
<span><i class="icon-minus-sign"></i> Great Grand Child</span> <a href="">Goes somewhere</a>
<ul>
<li>
<span><i class="icon-leaf"></i> Great great Grand Child</span> <a href="">Goes somewhere</a>
</li>
<li>
<span><i class="icon-leaf"></i> Great great Grand Child</span> <a href="">Goes somewhere</a>
</li>
</ul>
</li>
<li>
<span><i class="icon-leaf"></i> Great Grand Child</span> <a href="">Goes somewhere</a>
</li>
<li>
<span><i class="icon-leaf"></i> Great Grand Child</span> <a href="">Goes somewhere</a>
</li>
</ul>
</li>
<li>
<span><i class="icon-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<span><i class="icon-folder-open"></i> Parent2</span> <a href="">Goes somewhere</a>
<ul>
<li>
<span><i class="icon-leaf"></i> Child</span> <a href="">Goes somewhere</a>
</li>
</ul>
</li>
</ul>
</div>

<div class="tree">
<ul>
<li>
<span><i class="icon-calendar"></i> 2013, Week 2</span>
<ul>
<li>
<span class="badge badge-success"><i class="icon-minus-sign"></i> Monday, January 7: 8.00 hours</span>
<ul>
<li>
<a href=""><span><i class="icon-time"></i> 8.00</span> – Changed CSS to accomodate...</a>
</li>
</ul>
</li>
<li>
<span class="badge badge-success"><i class="icon-minus-sign"></i> Tuesday, January 8: 8.00 hours</span>
<ul>
<li>
<span><i class="icon-time"></i> 6.00</span> – <a href="">Altered code...</a>
</li>
<li>
<span><i class="icon-time"></i> 2.00</span> – <a href="">Simplified our approach to...</a>
</li>
</ul>
</li>
<li>
<span class="badge badge-warning"><i class="icon-minus-sign"></i> Wednesday, January 9: 6.00 hours</span>
<ul>
<li>
<a href=""><span><i class="icon-time"></i> 3.00</span> – Fixed bug caused by...</a>
</li>
<li>
<a href=""><span><i class="icon-time"></i> 3.00</span> – Comitting latest code to Git...</a>
</li>
</ul>
</li>
<li>
<span class="badge badge-important"><i class="icon-minus-sign"></i> Wednesday, January 9: 4.00 hours</span>
<ul>
<li>
<a href=""><span><i class="icon-time"></i> 2.00</span> – Create component that...</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<span><i class="icon-calendar"></i> 2013, Week 3</span>
<ul>
<li>
<span class="badge badge-success"><i class="icon-minus-sign"></i> Monday, January 14: 8.00 hours</span>
<ul>
<li>
<span><i class="icon-time"></i> 7.75</span> – <a href="">Writing documentation...</a>
</li>
<li>
我向往出来就是一个树根 树枝什么的都不打开
<span><i class="icon-time"></i> 0.25</span> – <a href="">Reverting code back to...</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

</body>
</html>
打开是这样的
...全文
119 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhangyikai321 2015-12-01
引用 楼主 zhangyikai321 的回复:
代码贴出来了 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery实现多级树形分类可折叠菜单特效代码</title> <!--图标样式--> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" /> <!--主要样式--> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> <div class="tree well"> <ul> <li> <span><i class="icon-folder-open"></i> Parent</span> <a href="">Goes somewhere</a> <ul> <li> <span><i class="icon-minus-sign"></i> Child</span> <a href="">Goes somewhere</a> <ul> <li> <span><i class="icon-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a> </li> </ul> </li> <li> <span><i class="icon-minus-sign"></i> Child</span> <a href="">Goes somewhere</a> <ul> <li> <span><i class="icon-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a> </li> <li> <span><i class="icon-minus-sign"></i> Grand Child</span> <a href="">Goes somewhere</a> <ul> <li> <span><i class="icon-minus-sign"></i> Great Grand Child</span> <a href="">Goes somewhere</a> <ul> <li> <span><i class="icon-leaf"></i> Great great Grand Child</span> <a href="">Goes somewhere</a> </li> <li> <span><i class="icon-leaf"></i> Great great Grand Child</span> <a href="">Goes somewhere</a> </li> </ul> </li> <li> <span><i class="icon-leaf"></i> Great Grand Child</span> <a href="">Goes somewhere</a> </li> <li> <span><i class="icon-leaf"></i> Great Grand Child</span> <a href="">Goes somewhere</a> </li> </ul> </li> <li> <span><i class="icon-leaf"></i> Grand Child</span> <a href="">Goes somewhere</a> </li> </ul> </li> </ul> </li> <li> <span><i class="icon-folder-open"></i> Parent2</span> <a href="">Goes somewhere</a> <ul> <li> <span><i class="icon-leaf"></i> Child</span> <a href="">Goes somewhere</a> </li> </ul> </li> </ul> </div> <div class="tree"> <ul> <li> <span><i class="icon-calendar"></i> 2013, Week 2</span> <ul> <li> <span class="badge badge-success"><i class="icon-minus-sign"></i> Monday, January 7: 8.00 hours</span> <ul> <li> <a href=""><span><i class="icon-time"></i> 8.00</span> – Changed CSS to accomodate...</a> </li> </ul> </li> <li> <span class="badge badge-success"><i class="icon-minus-sign"></i> Tuesday, January 8: 8.00 hours</span> <ul> <li> <span><i class="icon-time"></i> 6.00</span> – <a href="">Altered code...</a> </li> <li> <span><i class="icon-time"></i> 2.00</span> – <a href="">Simplified our approach to...</a> </li> </ul> </li> <li> <span class="badge badge-warning"><i class="icon-minus-sign"></i> Wednesday, January 9: 6.00 hours</span> <ul> <li> <a href=""><span><i class="icon-time"></i> 3.00</span> – Fixed bug caused by...</a> </li> <li> <a href=""><span><i class="icon-time"></i> 3.00</span> – Comitting latest code to Git...</a> </li> </ul> </li> <li> <span class="badge badge-important"><i class="icon-minus-sign"></i> Wednesday, January 9: 4.00 hours</span> <ul> <li> <a href=""><span><i class="icon-time"></i> 2.00</span> – Create component that...</a> </li> </ul> </li> </ul> </li> <li> <span><i class="icon-calendar"></i> 2013, Week 3</span> <ul> <li> <span class="badge badge-success"><i class="icon-minus-sign"></i> Monday, January 14: 8.00 hours</span> <ul> <li> <span><i class="icon-time"></i> 7.75</span> – <a href="">Writing documentation...</a> </li> <li> 我向往出来就是一个树根 树枝什么的都不打开 <span><i class="icon-time"></i> 0.25</span> – <a href="">Reverting code back to...</a> </li> </ul> </li> </ul> </li> </ul> </div> </body> </html> 打开是这样的
<script type="text/javascript"> $(function(){ $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch'); $(this).parent('li.parent_li').find(' > ul > li').hide('fast'); $('.tree li.parent_li > span').on('click', function (e) { var children = $(this).parent('li.parent_li').find(' > ul > li'); if (children.is(":visible")) { children.hide('fast'); $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign'); } else { children.show('fast'); $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign'); } e.stopPropagation(); }); }); 代码就是在这里但是我试了一下 还是不可以 啊
回复
guoquanhua007 2015-11-30
代码太长,不看啦。提供一个思路给你。 可以利用div嵌套默认不展示的数据display:none。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-11-30 01:40
社区公告
暂无公告