1、节点存在行为事件
后台代码:
1
2
3
4
5
6
7
8
|
// 子节点
TreeNode childNode =
new
TreeNode();
childNode.Target =
"main"
;
childNode.ShowCheckBox =
true
;
childNode.Value = category.CategoryID;
childNode.Text = category.CategoryName;
|
前台代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
//获取节点Text和Value值
function
GetNodeInfo() {
//获取选中的checkbox
//tv_category:TreeView控件ID
var
objs = $(
"#tv_category"
).find(
":checkbox:checked"
);
//装载Text和Value
var
select = [];
//遍历选中checkbox
$.each(objs,
function
() {
//获取列的href
var
href = $(
this
).next().attr(
"href"
);
//获取列的值
var
text = $(
this
).next().text();
//获得最后一次出现的索引
var
tempindex = href.lastIndexOf(
"\\"
) + 1;
//获得截取后的字符串
var
temphref= href.substring(tempindex);
//获得value值
var
hrefvalue = temphref.split(
'\''
);
var
textvalue = text +
"|"
+ hrefvalue[0];
select.push(textvalue);
});
alert(select.join(
"&"
));
//window.returnValue = select.join("&");
//window.close();
}
|
2、节点不存在行为事件
后台代码:
1
2
3
4
5
6
7
8
9
10
11
12
|
//子节点
TreeNode childNode =
new
TreeNode();
childNode.Target =
"main"
;
childNode.ShowCheckBox =
true
;
//设置节点行为为空
childNode.SelectAction = TreeNodeSelectAction.None;
//將value赋值给NavigateUrl便于前台href取值
childNode.NavigateUrl = category.CategoryID;
childNode.Value = category.CategoryID;
childNode.Text = category.CategoryName;
|
前台代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
//获取节点Text和Value值
function
GetNodeInfo() {
//获取选中的checkbox
var
objs = $(
"#tv_category"
).find(
":checkbox:checked"
);
//装载Text和Value
var
select = [];
//遍历选中checkbox
$.each(objs,
function
() {
//获取列的value
var
value = $(
this
).next().attr(
"href"
);
//获取列的值
var
text = $(
this
).next().text();
//Text和Value值
var
textvalue = text +
"|"
+ value;
select.push(textvalue);
});
alert(select.join(
"&"
));
//window.returnValue = select.join("&");
//window.close();
}
|
效果图: