ztree 彈窗實例

最近項目中用到ztree彈窗選擇,記錄作法javascript

1.彈出窗css

<script>
function seldep(){
	ret = window.showModalDialog('userselect.jsp?t=<%=System.currentTimeMillis()%>','人員選擇','dialogWidth=650px');
	if(ret && ret[0]!=''){
		editForm.users.value=ret[0];
		editForm.depart_id.value=ret[1];
	}
}
</script>
//文本框調用
<input type="text" name="users" value="(無)" readonly="1" onclick="seldep()" />
<input type="hidden" name="depart_id" id="depart_id"/>

 2.選擇頁面html

userselect.jspjava

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" 	src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.ztree.core-3.1.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.ztree.excheck-3.1.min.js"></script>
<link href="<%=request.getContextPath()%>/css/global.css" rel="stylesheet" type="text/css">
<link href="<%=request.getContextPath()%>/css/zTreeStyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
//數據組裝	
var zTreeObj;
		var setting = {
			check: {
				enable: false
				},
			view: {
				showIcon: false
			},
			data: {
			
					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeClick:beforeClick,
					onClick: zTreeOnClick
				}
		
		};
		var zNodes =[{ id:1, pId:0, name:"父節點1 - 展開", open:true},
				{ id:11, pId:1, name:"父節點11 - 摺疊"},
					{ id:111, pId:11, name:"葉子節點111"},
					{ id:112, pId:11, name:"葉子節點112"},
					{ id:113, pId:11, name:"葉子節點113"},
					{ id:114, pId:11, name:"葉子節點114"},
				{ id:12, pId:1, name:"父節點12 - 摺疊"},
					{ id:121, pId:12, name:"葉子節點121"},
					{ id:122, pId:12, name:"葉子節點122"},
					{ id:123, pId:12, name:"葉子節點123"},
					{ id:124, pId:12, name:"葉子節點124"},
				{ id:13, pId:1, name:"父節點13 - 沒有子節點", isParent:true},
			{ id:2, pId:0, name:"父節點2 - 摺疊"},
				{ id:21, pId:2, name:"父節點21 - 展開", open:true},
					{ id:211, pId:21, name:"葉子節點211"},
					{ id:212, pId:21, name:"葉子節點212"},
					{ id:213, pId:21, name:"葉子節點213"},
					{ id:214, pId:21, name:"葉子節點214"},
				{ id:22, pId:2, name:"父節點22 - 摺疊"},
					{ id:221, pId:22, name:"葉子節點221"},
					{ id:222, pId:22, name:"葉子節點222"},
					{ id:223, pId:22, name:"葉子節點223"},
					{ id:224, pId:22, name:"葉子節點224"},
				{ id:23, pId:2, name:"父節點23 - 摺疊"},
					{ id:231, pId:23, name:"葉子節點231"},
					{ id:232, pId:23, name:"葉子節點232"},
					{ id:233, pId:23, name:"葉子節點233"},
					{ id:234, pId:23, name:"葉子節點234"},
			{ id:3, pId:0, name:"父節點3 - 沒有子節點", isParent:true}
		];
		$(document).ready(function(){
			zTreeObj=$.fn.zTree.init($("#deps"), setting, zNodes);
		});
		function zTreeOnClick(event, treeId, treeNode) {
			var nodes = zTreeObj.getNodeByTId(treeNode.tId);
		  window.returnValue=new Array(nodes.name,nodes.id);
		  window.close(); 
		}
	function beforeClick(treeId, treeNode, clickFlag) {
			return (treeNode.click != false);
		}
		</script>
<title>部門選擇</title>
</head>
<body align="left">
	<div align="center" width="200px">
		<ul id="deps" class="ztree"></ul>
		
	</div>
</body>
</html>

效果圖:

 

相關文章
相關標籤/搜索