<td>现从事专业</td>
<td>
<asp:TextBox ID="tbMajor" runat="server" ReadOnly="true"></asp:TextBox>
<input type="hidden" id="hidV" runat="server" />
<input type="button" value="选择专业" onclick="OpenWin(300, 400);" />
</td>
<script type="text/javascript">
function OpenWin(width, height) {
var me;
// 把父页面窗体对象当作參数传递到对话框中。以便对话框操纵父页自己主动刷新。
me = window;
// 显示对话框。
var a = window.showModalDialog("MajorTree.aspx", me, 'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;help:no;status=no,toolbar=no,menubar=no,scrollbars=no,location=no');
if (typeof (a) != "undefined")
var str = new Array();
str = a.split("|");
var text = str[1];
var textv = str[0];
//返回值赋给TextBox
window.document.getElementById("tbMajor").value = text;
window.document.getElementById("hidV").value = textv;
}
</script>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MajorTree.aspx.cs" Inherits="ProvincePlat.EnergyService.MajorTree" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="../Css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<script src="../Js/jquery-1.7.2.min.js"></script>
<script src="../Js/jquery.ztree.core-3.5.min.js"></script>
<link href="../Css/master.css" rel="stylesheet" />
<link href="../Css/GridView.css" rel="stylesheet" />
<!-- 防止又一次打开页面形式的对话框 -->
<base target="_self" />
<script type="text/javascript">
var zNodes;
var zTree;
//setting异步载入的设置
var setting = {
async: {
enable: true, //表示异步载入生效
url: "../Ajax/MajorData.aspx", // 异步载入时訪问的页面
autoParam: ["id"], // 异步载入时自己主动提交的父节点属性的參数
otherParam: ["ajaxMethod", 'AnsyData'], //ajax请求时提交的參数
type: 'post',
dataType: 'json'
},
checkable: true,
showIcon: true,
showLine: true, // zTree显示连接线
data: { //用pId来标识父子节点的关系
simpleData: {
enable: true
}
},
expandSpeed: "", // 设置 zTree 节点展开、折叠的动画速度。默觉得"fast",""表示无动画
callback: { // 回调函数
onClick: zTreeOnClick, // 单击鼠标事件
asyncSuccess: zTreeOnAsyncSuccess //异步载入成功事件
}
};
$(document).ready(function () {
InitMajor();
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});
//初始化载入节点
function InitMajor() {
$.ajax({
url: '../Ajax/MajorData.aspx',
type: 'post',
dataType: 'json',
async: false,
data: { 'ajaxMethod': 'FirstAnsyData' },
success: function (data) {
zNodes = data;
}
});
};
//单击时获取zTree节点的Id,和value的值
function zTreeOnClick(event, treeId, treeNode, clickFlag) {
var treeValue = treeNode.id + "," + treeNode.name;
//单击给文本框赋值
var Id = treeNode.pId;
var v = "";
if (Id == '' || Id == undefined || Id == null) {
v = treeNode.name;
}
else {
v = treeNode.name;
}
//这里获取到文件夹树点击后的值
window.returnValue = treeNode.id + "|" + treeNode.name;
window.close();
};
function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div style="text-align: center;" class="midtitle">
专业类别
</div>
<div class="midtitle">
<ul id="treeDemo" class="ztree"></ul>
</div>
</div>
</form>
</body>
</html>
===========================================================================
假设觉得对您有帮助。微信扫一扫支持一下: