Bootstrap風格zTree樹形菜單插件

這是一款bootstrap風格jQuery zTree樹形菜單插件,支持自定義編輯、添加列表菜單、刪除列表等功能的jQuery樹形菜單代碼。在線演示javascript

具體代碼實現:css

<!DOCTYPE html>
<HTML>
<HEAD>
    <TITLE>ZTREE DEMO</TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link rel="stylesheet" href="css/bootstrapztree.css" type="text/css">
    
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="js/jquery.ztree.exedit.js"></script>
    <SCRIPT type="text/javascript">
        <!--
        var setting = {
            view: {
                addHoverDom: addHoverDom,
                removeHoverDom: removeHoverDom,
                selectedMulti: false
            },
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            edit: {
                enable: true
            }
        };

        var zNodes =[
        {id:1, pId:0, name:"[core] 基本功能 演示", open:true},
        {id:101, pId:1, name:"最簡單的樹 --  標準 JSON 數據"},
        {id:102, pId:1, name:"最簡單的樹 --  簡單 JSON 數據"},
        {id:103, pId:1, name:"不顯示 鏈接線"},
        {id:104, pId:1, name:"不顯示 節點 圖標"},
        {id:108, pId:1, name:"異步加載 節點數據"},
        {id:109, pId:1, name:"用 zTree 方法 異步加載 節點數據"},
        {id:110, pId:1, name:"用 zTree 方法 更新 節點數據"},
        {id:111, pId:1, name:"單擊 節點 控制"},
        {id:112, pId:1, name:"展開 / 摺疊 父節點 控制"},
        {id:113, pId:1, name:"根據 參數 查找 節點"},
        {id:114, pId:1, name:"其餘 鼠標 事件監聽"},
        {id:115, pId:114, name:"鼠標 事件監聽"},

        {id:2, pId:0, name:"[excheck] 復/單選框功能 演示", open:false},
        {id:201, pId:2, name:"Checkbox 勾選操做"},
        {id:206, pId:2, name:"Checkbox nocheck 演示"},
        {id:207, pId:2, name:"Checkbox chkDisabled 演示"},
        {id:208, pId:2, name:"Checkbox halfCheck 演示"},
        {id:202, pId:2, name:"Checkbox 勾選統計"},
        {id:203, pId:2, name:"用 zTree 方法 勾選 Checkbox"},
        {id:204, pId:2, name:"Radio 勾選操做"},
        {id:209, pId:2, name:"Radio nocheck 演示"},
        {id:210, pId:2, name:"Radio chkDisabled 演示"},
        {id:211, pId:2, name:"Radio halfCheck 演示"},
        {id:205, pId:2, name:"用 zTree 方法 勾選 Radio"},

        {id:3, pId:0, name:"[exedit] 編輯功能 演示", open:false},
        {id:301, pId:3, name:"拖拽 節點 基本控制"},
        {id:302, pId:3, name:"拖拽 節點 高級控制"},
        {id:303, pId:3, name:"用 zTree 方法 移動 / 複製 節點"},
        {id:304, pId:3, name:"基本 增 / 刪 / 改 節點"},
        {id:305, pId:3, name:"高級 增 / 刪 / 改 節點"},
        {id:306, pId:3, name:"用 zTree 方法 增 / 刪 / 改 節點"},
        {id:307, pId:3, name:"異步加載 & 編輯功能 共存"},
        {id:308, pId:3, name:"多棵樹之間 的 數據交互"},

        {id:4, pId:0, name:"大數據量 演示", open:false},
        {id:401, pId:4, name:"一次性加載大數據量"},
        {id:402, pId:4, name:"分批異步加載大數據量"},
        {id:403, pId:4, name:"分批異步加載大數據量"},

        {id:5, pId:0, name:"組合功能 演示", open:false},
        {id:501, pId:5, name:"凍結根節點"},
        {id:502, pId:5, name:"單擊展開/摺疊節點"},
        {id:503, pId:5, name:"保持展開單一路徑"},
        {id:504, pId:5, name:"添加 自定義控件"},
        {id:505, pId:5, name:"checkbox / radio 共存"},
        {id:506, pId:5, name:"左側菜單"},
        {id:507, pId:5, name:"下拉菜單"},
        {id:509, pId:5, name:"帶 checkbox 的多選下拉菜單"},
        {id:510, pId:5, name:"帶 radio 的單選下拉菜單"},
        {id:508, pId:5, name:"右鍵菜單 的 實現"},
        {id:511, pId:5, name:"與其餘 DOM 拖拽互動"},
        {id:512, pId:5, name:"異步加載模式下所有展開"},

        {id:6, pId:0, name:"其餘擴展功能 演示", open:false},
        {id:601, pId:6, name:"隱藏普通節點"},
        {id:602, pId:6, name:"配合 checkbox 的隱藏"},
        {id:603, pId:6, name:"配合 radio 的隱藏"}
        ];

        $(document).ready(function(){
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        });

        var newCount = 1;
        function addHoverDom(treeId, treeNode) {
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                + "' title='add node' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            var btn = $("#addBtn_"+treeNode.tId);
            if (btn) btn.bind("click", function(){
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
                return false;
            });
        };
        function removeHoverDom(treeId, treeNode) {
            $("#addBtn_"+treeNode.tId).unbind().remove();
        };
        //-->
    </SCRIPT>
</HEAD>

<BODY>
<h1>zTree - bootstrap 風格</h1>
<ul id="treeDemo" class="ztree"></ul>
</BODY>
</HTML>

源碼下載html

相關文章
相關標籤/搜索