首页 > Web开发 > 详细

jquery ui dialog和ztree简单结合

时间:2015-01-12 02:12:05      阅读:512      评论:0      收藏:0      [点我收藏+]
<head>
	<meta charset="utf-8">
	<title>jQuery UI Dialog - Modal form</title>
	<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.10.4.custom.min.css">
	<link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css">
	<script src="js/jquery-1.10.2.js"></script>
	
	<script src="js/jquery-ui-1.10.4.custom.min.js"></script>
	<script src="js/jquery.ztree.core-3.5.js"></script>
	<script src="js/jquery.ztree.excheck-3.5.js"></script>

	<script>
	$(function() {
	
		var setting = {
			check: {
				enable: true,
				chkStyle: "radio",
				radioType: "all"
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};
		
		var zNodes =[
			{ id:1, pId:0, name:"随意勾选 1", open:true},
			{ id:11, pId:1, name:"随意勾选 1-1", open:true},
			{ id:111, pId:11, name:"随意勾选 1-1-1"},
			{ id:112, pId:11, name:"随意勾选 1-1-2"},
			{ id:12, pId:1, name:"随意勾选 1-2", open:true},
			{ id:121, pId:12, name:"随意勾选 1-2-1"},
			{ id:122, pId:12, name:"随意勾选 1-2-2"},
			{ id:2, pId:0, name:"随意勾选 2", checked:true, open:true},
			{ id:21, pId:2, name:"随意勾选 2-1"},
			{ id:22, pId:2, name:"随意勾选 2-2", open:true},
			{ id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
			{ id:222, pId:22, name:"随意勾选 2-2-2"},
			{ id:23, pId:2, name:"随意勾选 2-3"}
		];
		
		
		

		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				"确定": function() {
					
					var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
					var nodes = treeObj.getCheckedNodes(true);
					var result = "";
					var tt = "";
					for(var i=0;i<nodes.length;i++){
						if(!nodes[i].isParent){
							result += nodes[i].name + ",";
							tt = nodes[i].id;
						}
					}
					$("#deptList").html(result);
					$("#deptid").val(tt);
					$( this ).dialog( "close" );
				},
				"取消": function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				
			}
		});

		$( "#create-user" )
			.button()
			.click(function() {
				$.fn.zTree.init($("#treeDemo"), setting, zNodes);
				$( "#dialog-form" ).dialog( "open" );
			});
	});
	</script>
</head>
<body>

<div id="dialog-form" title="部门结构" >
	<div style="z-index:990;">
	<ul id="treeDemo" class="ztree"></ul>
	</div>
</div>

<button id="create-user">选择部门</button>

<span id="deptList"></span>
<input id="deptid" type="text" value="">
<div class="demo-description">

</body>
</html>

?

jquery ui dialog和ztree简单结合

原文:http://yynwpf.iteye.com/blog/2174887

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!