jQuery获取TreeView选中节点的Text和Value值[转]
1、节点存在行为事件
后台代码:
// 子节点
TreeNode childNode = new TreeNode();
childNode.Target = "main" ;
childNode.ShowCheckBox = true ;
childNode.Value = category.CategoryID;
childNode.Text = category.CategoryName;
前台代码:
```javascript
//获取节点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();
}
```javascript
2、节点不存在行为事件
后台代码:
//子节点
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;
前台代码:
//获取节点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();
}