惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
IT之家
IT之家
B
Blog
博客园_首页
量子位
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
J
Java Code Geeks
H
Help Net Security
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
D
DataBreaches.Net
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News

博客园 - 郭大侠

asp.net获得路径的方法 用表格实现简单网站左侧导航 div里面套3个div,居中显示,兼容ie6-8,ff,咋就这么麻烦呢 网站设计之asp.net网站多语言版本 vs2005常用快捷键 Repeater显示父子表数据,无闪烁 jquery学习相关 show div and mouse can move on the div js map js+div+css 模拟弹出对话框 送大家一首歌曲,《保卫延安》片尾曲 vs2005调试javascript url重写 总有人问js二级联动问题,给出我写的一个例子 - 郭大侠 - 博客园 oracle横表变竖表问题 中国房地产的实质 北京奥运会赛事电视直播表(绝对完整)--每天就抱着电视看吧! 动物为什么会预知地震,地震后为什么会下雨? 新工资税计算方法及年终奖个税算法
【原创】还有比我这更简单的静态树吗? - 郭大侠 - 博客园
郭大侠 · 2010-12-06 · via 博客园 - 郭大侠

   coding这么多年,我居然不知道有"dl"这种html标记,惭愧啊,今天偶然发现,觉得好玩,如是我为它添加了折叠功能,变成了一颗静态树,谁有兴趣的话可以改成动态加载数据,或者用jquery,代码肯定会少很多!我发现添加一些css,这棵树在静态页面还是大有用途的!

<!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>
    
<style type="text/css">
        .expand
{
            cursor
:pointer;
        
}
        .hide
{
            cursor
:pointer;
        
}
    
</style>
    
    
<script type="text/javascript">
        
function toggleChild(o)
        {
            
var cls = o.getAttribute("class");
            
if (cls == "expand")
            {
                
var sb = o.nextSibling;
                
if (window.innerWidth) sb = sb.nextSibling;
                
while (sb != null && sb.tagName.toLowerCase() == 'dd')
                {
                    sb.style.display 
= "none";
                    sb 
= sb.nextSibling;
                    
if (window.innerWidth) sb = sb.nextSibling;
                }
                o.removeAttribute(
"class");
                o.setAttribute(
"class""hide");
                
if (window.innerWidth)  //ff
                    o.textContent = "" + o.textContent.substring(1);
                
else
                    o.innerText 
= "" + o.innerText.substring(1);
            }
            
else
            {
                
var sb = o.nextSibling;
                
if (window.innerWidth) sb = sb.nextSibling;
                
while (sb != null && sb.tagName.toLowerCase() == 'dd')
                {
                    sb.style.display 
= "";
                    sb 
= sb.nextSibling;
                    
if (window.innerWidth) sb = sb.nextSibling;
                }
                o.removeAttribute(
"class");
                o.setAttribute(
"class""expand");
                
if (window.innerWidth)  //ff
                    o.textContent = "" + o.textContent.substring(1);
                
else
                    o.innerText 
= "" + o.innerText.substring(1);
            }
        }
function maketree(obj)
        {
            
var dts = obj.getElementsByTagName('dt');
            
for (var i = 0; i < dts.length; i++)
            {
                dts[i].setAttribute(
"class""expand");
                
if (window.innerWidth)  //ff
                    dts[i].textContent = "" + dts[i].textContent;
                
else
                    dts[i].innerText 
= "" + dts[i].innerText;
                dts[i].onclick 
= function() { toggleChild(this); };
            }
        }
        
        window.onload 
= function()
        {
            maketree(document.getElementById(
"tree"));
        };
    
</script>
</head>
<body><h3>定义列表也能变成一棵树:</h3><dl id="tree">
    
<dt>菜单1</dt>
        
<dd>1.1 aaa</dd>
        
<dd>1.2 bbb</dd>
        
<dd>1.3 ccc</dd>
    
<dt>菜单2</dt>
        
<dd>2.1 你好</dd>
        
<dd><href='http://www.baidu.com'>超链接</a></dd>
    
<dt>菜单3</dt>
        
<dd>
            
<dl style="margin-top:2px; margin-bottom:2px;">
                
<dt>3.1</dt>
                
<dd><href="http://news.baidu.com">百度新闻</a></dd>
                
<dd><href="http://news.sohu.com">搜狐新闻</a></dd>
                
<dt>3.2</dt>
                
<dd><href="http://news.baidu.com">百度新闻</a></dd>
                
<dd><href="http://news.sohu.com">搜狐新闻</a></dd>
            
</dl>
        
</dd>
</dl>
</body>
</html>