jQuery插件zTree实现单独选中根节点中第⼀个节点⽰例本⽂实例讲述了jQuery插件zTree实现单独选中根节点中第⼀个节点的⽅法。分享给⼤家供⼤家参考,具体如下:
1、实现代码:
<!DOCTYPE html>
<html>
<head>
<title>zTree实现基本树</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/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:"黄⽯港区"},
{ id:122, pId:12, name:"西塞⼭区"},
{ id:123, pId:12, name:"下陆区"},
{ id:124, pId:12, name:"铁⼭区"},
{ id:13, pId:1, name:"黄冈市"},
{ id:131, pId:13, name:"黄州区"},
{ id:132, pId:13, name:"⿇城市"},
{ id:133, pId:13, name:"武⽳市"},
{ id:134, pId:13, name:"团风县"},
{ 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:"芙蓉区"},
{ id:212, pId:21, name:"天⼼区"},
{ id:213, pId:21, name:"岳麓区"},
{ id:214, pId:21, name:"开福区"},
{ id:22, pId:2, name:"株洲市"},
{ id:221, pId:22, name:"天元区"},
{ id:222, pId:22, name:"荷塘区"},
{ id:223, pId:22, name:"芦淞区"},
{ id:224, pId:22, name:"⽯峰区"}
];
$(document).ready(function(){
$.fn.zTree.init($("#baseTree"), setting, zNodes);
});
/
**
* 单独选中根节点中第⼀个节点
*/
function selectNodes()
{
var treeObj = $.ZTreeObj("baseTree");
//获取节点
var nodes = Nodes();
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" ></ul>
<input type="button" id="btn" onclick="selectNodes()" value="单独选中根节点中第⼀个节点"/>
</div>
</div>
</body>
</html>
2、实现效果图:
3、源码说明
单独选中根节点中第⼀个节点jquery插件分享
var node = treeObj.selectNode(nodes[0]);
附:zTree_v3插件点击此处。
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》及《》希望本⽂所述对⼤家jQuery程序设计有所帮助。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论