本文实例讲述了jQuery插件最好实现单独选中根节点中第一个节点的方法。分享给大家供大家参考,具体如下:
1,实现代码:
& lt; !DOCTYPE html> & lt; html> & lt; head> & lt; title>最好实现基本树& lt;/title> & lt;元http-equiv=? type”内容=" text/html;charset=utf - 8”比; & lt;链接rel="样式表" type=" text/css " href=" https://www.yisu.com/zixun/zTree_v3/css/demo.css " rel=巴獠縩ofollow”比; & lt;链接rel="样式表" type=" text/css " href=" https://www.yisu.com/zixun/zTree_v3/css/zTreeStyle/zTreeStyle.css " rel=巴獠縩ofollow”比; & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/zTree_v3/js/jquery-1.4.4.min.js "祝辞& lt;/script> & lt;脚本type=" text/javascript " src=" https://www.yisu.com/zixun/zTree_v3/js/jquery.ztree.core.min.js "祝辞& lt;/script> & lt;脚本type=" text/javascript祝辞 & lt; !={var设置 数据:{ simpleData: { 启用:真 } } }; var zNodes=[ {id: 1、pId: 0,名字:“湖北省”,开放:真正的}, pId {id: 11日:1、名称:“武汉市”,开放:真正的}, {id: 111年,pId: 11日,名字:“汉口"}, {id: 112年,pId: 11日,名字:“汉阳"}, {id: 113年,pId: 11日,名字:“武昌"}, {id: 12, pId: 1,名字:“黄石市"}, {id: 121年,pId: 12,名字:“黄石港区"}, {id: 122年,pId: 12,名字:“西塞山区"}, {id: 123年,pId: 12,名字:“下陆区"}, {id: 124年,pId: 12,名字:“铁山区"}, pId {id: 13日:1、名称:“黄冈市"}, {id: 131年,pId: 13岁的名字:“黄州区"}, {id: 132年,pId: 13岁的名字:“麻城市"}, {id: 133年,pId: 13岁的名字:“武穴市"}, {id: 134年,pId: 13岁的名字:“团风县"}, {id: 135年,pId: 13岁的名字:“浠水县"}, {id: 136年,pId: 13岁的名字:“罗田县"}, {id: 137年,pId: 13岁的名字:“英山县"}, {id: 2, pId: 0,名字:“湖南省”,开放:真正的}, {pId id: 21日:2,名字:“长沙市”,开放:真正的}, {id: 211年,pId: 21岁的名字:“芙蓉区"}, {id: 212年,pId: 21岁的名字:“天心区"}, {id: 213年,pId: 21岁的名字:“岳麓区"}, {id: 214年,pId: 21岁的名字:“开福区"}, {pId id: 22日:2,名字:“株洲市"}, {id: 221年,pId: 22岁的名字:“天元区"}, {id: 222年,pId: 22岁的名字:“荷塘区"}, {id: 223年,pId: 22岁的名字:“芦淞区"}, {id: 224年,pId: 22岁的名字:“石峰区”} ]; $(文档)时函数(){ (.fn.zTree.init美元(“# baseTree”),设置,zNodes); });/* * *单独选中根节点中第一个节点 */selectNodes()函数 { var treeObj=$ .fn.zTree.getZTreeObj (“baseTree”);//获取节点 var=treeObj.getNodes节点(); 如果(nodes.length> 0) { var=treeObj.selectNode节点(节点[0]); 警报(节点); } }//? & lt;/script> & lt;/head> & lt; body> & lt; div类=癱ontent_wrap”比; & lt; div class=" zTreeDemoBackground左”比; & lt; ul类id=癰aseTree”=白詈谩弊4? lt;/ul> & lt;输入类型="按钮" id=" btn " value=" https://www.yisu.com/zixun/单独选中根节点中第一个节点”/比; & lt;/div> & lt;/div> & lt;/body> & lt;/html> >之前2,实现效果图:
3,源码说明
单独选中根节点中第一个节点
var=treeObj.selectNode节点(节点[0]); >之前<强>附:强> zTree_v3插件点击此处。
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery常用插件及用法总结》,《jQuery Ajax用中法总结》,《jQuery表格(表)操作技巧汇总》、《jQuery扩展技巧总结》,《jQuery常见经典特效汇总》及《jQuery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
jQuery插件最好实现单独选中根节点中第一个节点示例