jQuery插件zTree實(shí)現(xiàn)的基本樹(shù)與節(jié)點(diǎn)獲取操作示例
本文實(shí)例講述了jQuery插件zTree實(shí)現(xiàn)的基本樹(shù)與節(jié)點(diǎn)獲取操作。分享給大家供大家參考,具體如下:
1、實(shí)現(xiàn)代碼:
<!DOCTYPE html> <html> <head> <title>zTree實(shí)現(xiàn)基本樹(shù)</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="zTree_v3/css/demo.css" rel="external nofollow" > <link rel="stylesheet" type="text/css" href="zTree_v3/css/zTreeStyle/zTreeStyle.css" rel="external nofollow" > <script type="text/javascript" src="zTree_v3/js/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="zTree_v3/js/jquery.ztree.core.min.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:"漢陽(yáng)"}, { 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:2, pId:0, name:"湖南省", open:true}, { id:21, pId:2, name:"長(zhǎng)沙市", 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:"開(kāi)福區(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ū)"}, { id:23, pId:2, name:"湘潭市"}, { id:231, pId:23, name:"雨湖區(qū)"}, { id:232, pId:23, name:"岳塘區(qū)"}, { id:233, pId:23, name:"湘鄉(xiāng)市"}, { id:234, pId:23, name:"韶山市"} ]; $(document).ready(function(){ $.fn.zTree.init($("#baseTree"), setting, zNodes); }); /** * 獲取選中節(jié)點(diǎn)的編碼和名稱 */ function findSelect() { var treeObj = $.fn.zTree.getZTreeObj("baseTree"); var nodes = treeObj.getSelectedNodes(); for(var i=0;i<nodes.length;i++) { var nodeId = nodes[i].id; var nodeName = nodes[i].name; alert("樹(shù)節(jié)點(diǎn)編碼:"+nodeId+"\n"+"樹(shù)節(jié)點(diǎn)名稱:"+nodeName); } } //--> </script> </head> <body> <div class="content_wrap"> <div class="zTreeDemoBackground left" style="text-align: center;"> <ul id="baseTree" class="ztree" style="height: 300px; width:200px; overflow-y: auto"></ul> <input type="button" id="btn" onclick="findSelect()" value="獲取選中節(jié)點(diǎn)"/> </div> </div> </body> </html>
2、設(shè)計(jì)效果圖:
(1)初始化
(2)單擊按鈕
3、設(shè)計(jì)說(shuō)明
獲取 zTree 當(dāng)前被選中的節(jié)點(diǎn)數(shù)據(jù)集合
var treeObj = $.fn.zTree.getZTreeObj("baseTree"); var nodes = treeObj.getSelectedNodes();
附:zTree_v3插件點(diǎn)擊此處本站下載。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- ztree獲取當(dāng)前選中節(jié)點(diǎn)子節(jié)點(diǎn)id集合的方法
- js樹(shù)插件zTree獲取所有選中節(jié)點(diǎn)數(shù)據(jù)的方法
- 后臺(tái)獲取ZTREE選中節(jié)點(diǎn)的方法
- zTree實(shí)現(xiàn)節(jié)點(diǎn)修改的實(shí)時(shí)刷新功能
- 在父頁(yè)面得到zTree已選中的節(jié)點(diǎn)的方法
- ztree獲取選中節(jié)點(diǎn)時(shí)不能進(jìn)入可視區(qū)域出現(xiàn)BUG如何解決
- jQuery插件zTree實(shí)現(xiàn)刪除樹(shù)節(jié)點(diǎn)的方法示例
- zTree異步加載展開(kāi)第一級(jí)節(jié)點(diǎn)的實(shí)現(xiàn)方法
- jQuery插件zTree實(shí)現(xiàn)清空選中第一個(gè)節(jié)點(diǎn)所有子節(jié)點(diǎn)的方法
- zTree節(jié)點(diǎn)文字過(guò)多的處理方法
相關(guān)文章
簡(jiǎn)單談?wù)刯Query(function(){})與(function(){})(jQuery)
這篇文章主要簡(jiǎn)單介紹了jQuery(function(){})與(function(){})(jQuery)的區(qū)別,需要的朋友可以參考下2014-12-12jQuery插件HighCharts繪制的基本折線圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts繪制的基本折線圖效果,結(jié)合實(shí)例形式分析了jQuery基于HighCharts插件繪制圖形的具體實(shí)現(xiàn)步驟與相關(guān)操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03jquery實(shí)現(xiàn)簡(jiǎn)單的瀑布流布局
瀑布流布局有兩種,一種是固定列,一種是非固定列。本文主要記述第一種的實(shí)現(xiàn)。需要的朋友可以參考借鑒2016-12-12jQuery解決下拉框select設(shè)寬度時(shí)IE 6/7/8下option超出顯示不全
jQuery解決IE 6/7/8 BUG:下拉框select設(shè)寬度時(shí)option超出顯示不全,經(jīng)過(guò)修改效果還不錯(cuò),遇到類似情況的朋友可以參考下哈2013-05-05基于jQuery實(shí)現(xiàn)仿百度首頁(yè)換膚背景圖片切換代碼
現(xiàn)在介紹網(wǎng)頁(yè)換膚的例子已經(jīng)數(shù)不勝數(shù),自己也沒(méi)有仔細(xì)研究過(guò),剛搞遇到類似這個(gè)問(wèn)題,網(wǎng)上查了資料解決了問(wèn)題,感覺(jué)很有用,就記錄了下來(lái),本文給大家分享基于jQuery實(shí)現(xiàn)仿百度首頁(yè)換膚背景圖片切換代碼,需要的朋友可以參考下2015-08-08JQuery 進(jìn)入頁(yè)面默認(rèn)給已賦值的復(fù)選框打鉤
這篇文章主要介紹了JQuery 進(jìn)入頁(yè)面默認(rèn)給已賦值的復(fù)選框打鉤的實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-03-03jQuery 開(kāi)發(fā)之EasyUI 添加數(shù)據(jù)的實(shí)例
這篇文章主要介紹了jQuery 開(kāi)發(fā)之EasyUI 添加數(shù)據(jù)的實(shí)例的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-09-09