日期:2014-05-19  浏览次数:20434 次

有那位高人知道asp2.0中用javascript如何循环的去读取treeview中所有父节点的value和text
有那位高人知道asp2.0中用javascript如何循环的去读取treeview中所有父节点的value和text(只有两层,没有根,不读取树叶)

------解决方案--------------------
大致做法
<%@ Page Language= "C# " %>
<script runat= "server ">
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.Attributes.Add( "onclick ", "OnClientTreeNodeChecked(event) ");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Request.Form[ "CheckedNode "] != null)
{
string CheckedNodeValue = Request.Form[ "CheckedNode "];
if (CheckedNodeValue == " ")
return;

if (CheckedNodeValue.EndsWith( ", "))
CheckedNodeValue = CheckedNodeValue.TrimEnd( ', ');

Response.Write( "您选择的节点有: "+CheckedNodeValue);
}
}
</script>

<html xmlns= "http://www.w3.org/1999/xhtml ">
<head id= "Head1 " runat= "server ">
<title> 客户端实现全选子节点 </title>
<script type= "text/javascript " language= "javascript ">
//识别不同的浏览器
function getTargetElement(evt) {
var elem
if (evt.target)
{
elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target
}
else
{
elem = evt.srcElement
}
return elem
}

function OnClientTreeNodeChecked(evt)
{
evt = (evt) ? evt : ((window.event) ? window.event : " ");
if(evt == " ")
{
return;
}
var obj = getTargetElement(evt);
var hasTreeNode = false;
if(obj.tagName)
{
if (obj.tagName == "INPUT " && obj.type == "checkbox ") {
var treeNode = obj;
while (obj.tagName != "TABLE ")
{
obj = obj.parentNode;
}
var parentTreeDeep = obj.rows[0].cells.length;
var parentTreeNode = obj.rows[0].cells[0];
var oDiv = obj.parentNode;
if( null == oDiv )
{
return;
}
if( 1 != oDiv.nodeType)
{
return;
}
var tables = oDiv.getElementsByTagName( "TABLE ");
if( null == tables)
{
return;
}
var tableCount = tables.length;
if(tableCount < 1)
{
return;
}
for (i = 0; i < tableCount; i++)
{
if ( obj == tables[i] )
{
hasTreeNode = true;
i++;
if (tableCount == i )
{
return;
}
}
if (hasTreeNode)
{
var childTreeDeep = tables[i].rows[0].cells.length;
if (childTreeDeep > parentTreeDeep)
{
var cellTreeNode = tables[i].rows[0].cells[childTreeDeep - 1];
var inputs = cellTreeNode.getElementsByTagName( "INPUT ");
if( null != inputs)
{
inputs[0].checked = treeNode.checked;
}
}
else
{
return;
}