zTree实现单独选中根节点中第一个节点
生活随笔
收集整理的這篇文章主要介紹了
zTree实现单独选中根节点中第一个节点
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
zTree實現(xiàn)單獨選中根節(jié)點中第一個節(jié)點
1、實現(xiàn)源代碼
<!DOCTYPE html> <html> <head><title>zTree實現(xiàn)基本樹</title><meta http-equiv="content-type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="../../../css/demo.css"><link rel="stylesheet" type="text/css" href="../../../css/zTreeStyle/zTreeStyle.css"><script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script><script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script><script type="text/javascript"><!--var setting = {data: {simpleData: {enable: true}}};var zNodes =[{ id:1, pId:0, name:"湖北省", open:true},{ id:11, pId:1, name:"武漢市", open:true},{ id:111, pId:11, name:"漢口"},{ id:112, pId:11, name:"漢陽"},{ id:113, pId:11, name:"武昌"},{ id:12, pId:1, name:"黃石市"},{ id:121, pId:12, name:"黃石港區(qū)"},{ id:122, pId:12, name:"西塞山區(qū)"},{ id:123, pId:12, name:"下陸區(qū)"},{ id:124, pId:12, name:"鐵山區(qū)"},{ id:13, pId:1, name:"黃岡市"},{ id:131, pId:13, name:"黃州區(qū)"},{ id:132, pId:13, name:"麻城市"},{ id:133, pId:13, name:"武穴市"},{ id:134, pId:13, name:"團(tuán)風(fēng)縣"},{ id:135, pId:13, name:"浠水縣"},{ id:136, pId:13, name:"羅田縣"},{ id:137, pId:13, name:"英山縣"},{ id:2, pId:0, name:"湖南省", open:true},{ id:21, pId:2, name:"長沙市", open:true},{ id:211, pId:21, name:"芙蓉區(qū)"},{ id:212, pId:21, name:"天心區(qū)"},{ id:213, pId:21, name:"岳麓區(qū)"},{ id:214, pId:21, name:"開福區(qū)"},{ id:22, pId:2, name:"株洲市"},{ id:221, pId:22, name:"天元區(qū)"},{ id:222, pId:22, name:"荷塘區(qū)"},{ id:223, pId:22, name:"蘆淞區(qū)"},{ id:224, pId:22, name:"石峰區(qū)"}];$(document).ready(function(){$.fn.zTree.init($("#baseTree"), setting, zNodes);});/*** 單獨選中根節(jié)點中第一個節(jié)點*/function selectNodes(){var treeObj = $.fn.zTree.getZTreeObj("baseTree");//獲取節(jié)點var nodes = treeObj.getNodes();if (nodes.length>0) {var node = treeObj.selectNode(nodes[0]);alert(node);}}//--></script></head><body> <div class="content_wrap"><div class="zTreeDemoBackground left"><ul id="baseTree" class="ztree" style="height: 300px; width:200px; overflow-y: auto"></ul><input type="button" id="btn" οnclick="selectNodes()" value="單獨選中根節(jié)點中第一個節(jié)點"/></div> </div> </body> </html>
2、實現(xiàn)結(jié)果
3、源代碼說明
單獨選中根節(jié)點中第一個節(jié)點
var node = treeObj.selectNode(nodes[0]);
轉(zhuǎn)載于:https://www.cnblogs.com/yutingliuyl/p/6973072.html
總結(jié)
以上是生活随笔為你收集整理的zTree实现单独选中根节点中第一个节点的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于XAMPP环境配置
- 下一篇: 支持向量机(理论+opencv实现)