jQuery插件zTree實(shí)現(xiàn)清空選中第一個(gè)節(jié)點(diǎn)所有子節(jié)點(diǎn)的方法
本文實(shí)例講述了jQuery插件zTree實(shí)現(xiàn)清空選中第一個(gè)節(jié)點(diǎ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: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);
});
/**
* 清空選中的第一個(gè)節(jié)點(diǎn)的子節(jié)點(diǎn)
*/
function removeChildNodesTree()
{
var treeObj = $.fn.zTree.getZTreeObj("baseTree");
//獲取全部節(jié)點(diǎn)數(shù)據(jù)
var nodes = treeObj.getNodes();
for (var i=0, l=nodes.length; i < l; i++)
{
//清空選中的第一個(gè)節(jié)點(diǎn)的子節(jié)點(diǎn)
treeObj.removeChildNodes(nodes[i]);
}
}
//-->
</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" onclick="removeChildNodesTree()" value="清空選中的第一個(gè)節(jié)點(diǎn)的子節(jié)點(diǎn)"/>
</div>
</div>
</body>
</html>
2、實(shí)現(xiàn)效果圖:
(1)初始化

(2)單擊按鈕

3、源碼說明:
//清空選中的第一個(gè)節(jié)點(diǎn)的子節(jié)點(diǎn) treeObj.removeChildNodes(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é)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery插件zTree實(shí)現(xiàn)刪除樹子節(jié)點(diǎn)的方法示例
- jquery獲取子節(jié)點(diǎn)和父節(jié)點(diǎn)的示例代碼
- jQuery循環(huán)遍歷子節(jié)點(diǎn)并獲取值的方法
- jQuery獲取節(jié)點(diǎn)和子節(jié)點(diǎn)文本的方法
- jquery實(shí)現(xiàn)點(diǎn)擊TreeView文本父節(jié)點(diǎn)展開/折疊子節(jié)點(diǎn)
- jquery 取子節(jié)點(diǎn)及當(dāng)前節(jié)點(diǎn)屬性值的方法
- jquery 取子節(jié)點(diǎn)及當(dāng)前節(jié)點(diǎn)屬性值
- jquery的父、子、兄弟節(jié)點(diǎn)查找,節(jié)點(diǎn)的子節(jié)點(diǎn)循環(huán)方法
- jQuery刪除/清空指定元素的所有子節(jié)點(diǎn)實(shí)例代碼
相關(guān)文章
jQuery基于事件控制實(shí)現(xiàn)點(diǎn)擊顯示內(nèi)容下拉效果
這篇文章主要介紹了jQuery基于事件控制實(shí)現(xiàn)點(diǎn)擊顯示內(nèi)容下拉效果,涉及jQuery事件響應(yīng)及元素屬性動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-03-03
jQuery 回調(diào)函數(shù)(callback)的使用和基礎(chǔ)
這篇文章主要介紹了jQuery 回調(diào)函數(shù)(callback)的使用和基礎(chǔ),需要的朋友可以參考下2015-02-02
使用jquery實(shí)現(xiàn)的循環(huán)連續(xù)可停頓滾動(dòng)實(shí)例
下面小編就為大家?guī)硪黄褂胘query實(shí)現(xiàn)的循環(huán)連續(xù)可停頓滾動(dòng)實(shí)例。2016-11-11
使用jQuery將多條數(shù)據(jù)插入模態(tài)框的實(shí)現(xiàn)代碼
這篇文章主要介紹了使用jQuery將多條數(shù)據(jù)插入模態(tài)框的方法,很簡(jiǎn)單,很實(shí)用,需要的朋友可以參考下2014-10-10
jQuery使用中可能被XSS攻擊的一些危險(xiǎn)環(huán)節(jié)提醒
XSS指的是跨站腳本攻擊,比如人們常說的向$傳入字符串或者字符串轉(zhuǎn)換可執(zhí)行函數(shù)等一些安全方面值得注意的細(xì)節(jié),下面就為大家整理了jQuery使用中可能被XSS攻擊的一些危險(xiǎn)環(huán)節(jié)提醒2016-05-05
30個(gè)經(jīng)典的jQuery代碼開發(fā)技巧
這篇文章主要介紹了30個(gè)經(jīng)典的jQuery代碼開發(fā)技巧,包含了常見屬性、方法、元素等的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12
幾種二級(jí)聯(lián)動(dòng)案例(jQuery\Array\Ajax php)
這篇文章主要為大家詳細(xì)介紹了幾種二級(jí)聯(lián)動(dòng)案例(jQuery\Array\Ajax php),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08

