日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

jQuery 無限級菜單實現(xiàn)

 集微筆記 2013-10-21
我將CSS完全分離出來用jQuery附加式樣,就是為了多級染色,并且生成目錄樹和控制式樣也很容易,生成時也不需要考慮式樣。數(shù)據(jù)表建議用事先Order排序的方式,不要讀取數(shù)據(jù)的時候才分級排序,這樣性能會較佳。

我把它做成了個.Net的控件,作為輕量級的無限目錄樹,還是相當好用的。只是還不完善,我先慢慢修改,等差不多了再發(fā)布出來。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www./1999/xhtml">
<head id="Head1" runat="server">
    
<title>jQuery 無限級菜單</title>
    
<style type="text/css">
    #menu a 
{
        color
:#fff;
    
}
    #menu div 
{
        
/* text-align:center; */
    
}
    #menu div a 
{
        padding-left
:20px;
    
}
    #menu div.root 
{
        display
:block;
    
}
    .list 
{ background:url(list.gif) no-repeat 6px 6px; }
    
</style>
    
<script type="text/javascript" language="javascript" src="jquery-1.2.3.min.js"></script>
    
<script type="text/javascript" language="javascript">
    $(
function(){
        
//顏色列表,如果想支持無限級,最好自動生成顏色列表,不過我的配色一項很差,用生成的就更慘不忍睹了……

        _cor = ['#003366''#0066CC''#3399FF''#990000''#CC0000''#FF3300''#FF9900''#FFCC66''#FFFFFF'];
        
//初始化類

        (function Init(i,obj){
            i
++
;
            
//查找子節(jié)點

            _obj = obj.children('div');
            
//若有子節(jié)點,則增加一個專有式樣

            if (_obj.length > 0)
                obj.addClass(
'list'
);
            $.each(_obj, 
function
(j,o){
                
//若是子目錄則隱藏

                if (i > 0)
                    $(o).hide();
                
//根據(jù)目錄級數(shù)查找顏色字典上背景色,可改為圖片什么的。

                $(o).css('background-color',_cor[i]);
                
//查找子目錄

                Init(i,$(o));
            });
        })(
-1,$('#menu'
));
    });
    
//跳轉(zhuǎn)鏈接

    function GotoURL(obj) {
        
//若鏈接最末一位不是符號“#”則跳轉(zhuǎn)鏈接,因為取href得到鏈接絕對路徑,所以只能取最后一位,其實可以傳值判斷或生成目錄樹時不產(chǎn)生onclick都是可以的

        if (obj.href.substring(obj.href.length - 1, obj.href.length) != "#"return true;
        
//拉出和縮進的特效

        $.each($(obj).parent().children('div'), function(i,o){
            $(o).slideToggle(
'slow'
);
        });
        
return false
;
    }
    
</script>

</head>
<body>

    
<div id="menu">
        
<div> <href="#" onclick="return GotoURL(this)">第一級</a> </div>
        
<div> <href="#" onclick="return GotoURL(this)">第一級</a>
            
<div> <href="#" onclick="return GotoURL(this)">第二級</a> </div>
            
<div> <href="#" onclick="return GotoURL(this)">第二級</a>
                
<div> <href="#" onclick="return GotoURL(this)">第三級</a>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a> </div>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a> </div>
                
</div>
                
<div> <href="#" onclick="return GotoURL(this)">第三級</a>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a> </div>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a>
                        
<div> <href="#" onclick="return GotoURL(this)">第五級</a> </div>
                        
<div> <href="#" onclick="return GotoURL(this)">第五級</a> </div>
                        
<div> <href="#" onclick="return GotoURL(this)">第五級</a>
                            
<div> <href="#" onclick="return GotoURL(this)">第六級</a> </div>
                            
<div> <href="#" onclick="return GotoURL(this)">第六級</a> </div>
                        
</div>
                    
</div>
                
</div>
            
</div>
            
<div> <href="#" onclick="return GotoURL(this)">第二級</a> </div>
        
</div>
        
<div> <href="#" onclick="return GotoURL(this)">第一級</a>
            
<div> <href="#" onclick="return GotoURL(this)">第二級</a> </div>
            
<div> <href="#" onclick="return GotoURL(this)">第二級</a> </div>
            
<div> <href="#" onclick="return GotoURL(this)">第二級</a>
                
<div> <href="#" onclick="return GotoURL(this)">第三級</a>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a> </div>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a> </div>
                
</div>
                
<div> <href="#" onclick="return GotoURL(this)">第三級</a>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a> </div>
                    
<div> <href="#" onclick="return GotoURL(this)">第四級</a>
                        
<div> <href="#" onclick="return GotoURL(this)">第五級</a> </div>
                        
<div> <href="#" onclick="return GotoURL(this)">第五級</a> </div>
                        
<div> <href="#" onclick="return GotoURL(this)">第五級</a>
                            
<div> <href="#" onclick="return GotoURL(this)">第六級</a> </div>
                            
<div> <href="#" onclick="return GotoURL(this)">第六級</a> </div>
                        
</div>
                    
</div>
                
</div>
            
</div>
        
</div>
    
</div>

</body>
</html>
轉(zhuǎn)自:http://blog.csdn.net/jpr1990/article/details/7245713

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約