jQuery插件zTree實(shí)現(xiàn)刪除樹節(jié)點(diǎn)的方法示例
本文實(shí)例講述了jQuery插件zTree實(shí)現(xiàn)刪除樹節(jié)點(diǎn)的方法。分享給大家供大家參考,具體如下:
1、實(shí)現(xiàn)代碼:
<!DOCTYPE html> <html> <head> <title>zTree實(shí)現(xiàn)基本樹</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:"漢陽"}, { 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:"長沙市", 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ū)"}, { 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 removeNodes() { var treeObj = $.fn.zTree.getZTreeObj("baseTree"); //選中節(jié)點(diǎn) var nodes = treeObj.getSelectedNodes(); for (var i=0, l=nodes.length; i < l; i++) { //刪除選中的節(jié)點(diǎn) treeObj.removeNode(nodes[i]); } } //--> </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="removeNodes()" value="刪除節(jié)點(diǎn)"/> </div> </div> </body> </html>
2、實(shí)現(xiàn)效果圖:
(1)初始化
(2)點(diǎn)擊“漢口”,再單擊“刪除節(jié)點(diǎn)”
3、說明
//刪除選中的節(jié)點(diǎn) treeObj.removeNode(nodes[i]);
附:zTree_v3插件點(diǎn)擊此處本站下載。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- ztree獲取當(dāng)前選中節(jié)點(diǎn)子節(jié)點(diǎn)id集合的方法
- js樹插件zTree獲取所有選中節(jié)點(diǎn)數(shù)據(jù)的方法
- 后臺獲取ZTREE選中節(jié)點(diǎn)的方法
- zTree實(shí)現(xiàn)節(jié)點(diǎn)修改的實(shí)時刷新功能
- 在父頁面得到zTree已選中的節(jié)點(diǎn)的方法
- ztree獲取選中節(jié)點(diǎn)時不能進(jìn)入可視區(qū)域出現(xiàn)BUG如何解決
- zTree異步加載展開第一級節(jié)點(diǎn)的實(shí)現(xiàn)方法
- jQuery插件zTree實(shí)現(xiàn)的基本樹與節(jié)點(diǎn)獲取操作示例
- jQuery插件zTree實(shí)現(xiàn)清空選中第一個節(jié)點(diǎn)所有子節(jié)點(diǎn)的方法
- zTree節(jié)點(diǎn)文字過多的處理方法
相關(guān)文章
基于jquery的當(dāng)鼠標(biāo)滾輪到最底端繼續(xù)加載新數(shù)據(jù)思路分享(多用于微博、空間、論壇 )
基于jquery的當(dāng)鼠標(biāo)滾輪到最底端繼續(xù)加載新數(shù)據(jù)思路分享(多用于微博、空間、論壇 ),需要的朋友可以參考下。2011-10-10jquery數(shù)據(jù)驗證插件(自制,簡單,練手)實(shí)例代碼
最近項目中js數(shù)據(jù)驗證比較多,為了統(tǒng)一風(fēng)格,移植復(fù)用,于是順手封裝了Jquery的插件2013-10-10基于JQuery實(shí)現(xiàn)圖片輪播效果(焦點(diǎn)圖)
這篇文章主要為大家詳細(xì)介紹了基于JQuery實(shí)現(xiàn)圖片輪播效果,利用Jquery制作焦點(diǎn)圖左右輪播特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-02-02jquery導(dǎo)航制件jquery鼠標(biāo)經(jīng)過變色效果示例
這篇文章主要介紹了jquery鼠標(biāo)經(jīng)過變色效果代碼,大家參考使用吧2013-12-12jQuery插件HighCharts實(shí)現(xiàn)的2D回歸直線散點(diǎn)效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts實(shí)現(xiàn)的2D回歸直線散點(diǎn)效果,結(jié)合實(shí)例形式分析了jQuery基于HighCharts插件繪制直線散點(diǎn)圖形的具體相關(guān)操作步驟與實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03jQuery基礎(chǔ)知識點(diǎn)總結(jié)(DOM操作)
下面小編就為大家?guī)硪黄猨Query基礎(chǔ)知識點(diǎn)總結(jié)(DOM操作)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06jquery+css實(shí)現(xiàn)絢麗的橫向二級下拉菜單-附源碼下載
這篇文章主要介紹了jquery+css實(shí)現(xiàn)絢麗的橫向二級下拉菜單-附源碼下載,需要的朋友可以參考下2015-08-08jQuery插件Flexslider實(shí)現(xiàn)圖片輪播、圖文結(jié)合滑動切換效果
這篇文章主要介紹了jQuery插件Flexslider實(shí)現(xiàn)圖片輪播、圖文結(jié)合滑動切換效果的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-07-07