`
yynwpf
  • 浏览: 10274 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
jquery ui dialog和ztree简单结合 jquery ui dialog, ztree
<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>
Global site tag (gtag.js) - Google Analytics