ASP.NET:通过客户端 JavaScript 在 ASP.NET TreeView 上选择节点

标签 asp.net javascript treeview

我需要从客户端的 ASP.NET Treeview 了解所选节点的深度。

有什么办法知道这一点吗?

谢谢!

最佳答案

并不是说我喜欢这样做,如果时间允许,我会尝试寻找其他方法;

        var id = TreeView2_Data.selectedNodeID.value;  //Get the Selectednode id of tv with asp.net id of TreeView2
    if (id.length > 0) {
        var selectedNode = document.getElementById(id);  //Get the Selectnode object  -> selectedNode.innerText will give you the text of the node
        if ((typeof (selectedNode) != "undefined") && (selectedNode != null)) {
            //Determine the depth of the select node
            var nodeDepth = selectedNode.host.split('\\\\').length  // the separator is the default single \. Tv adds the extra on and of course we have to add 2 for the string literals.
            //node depth wil always be one more than the real node depth, so root is one.
            if (nodeDepth >= 4) {   
                //Do stuff or return value
            }
        }
    }

希望有帮助。如果您找到替代方案,请回复。

关于ASP.NET:通过客户端 JavaScript 在 ASP.NET TreeView 上选择节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/897100/

相关文章:

javascript - Svg 文本元素被另一个 svg 元素重叠

c# - 将 TreeView 绑定(bind)到包含多个对象的单个对象

c# - 如何在返回 View 之前修改 Controller 中的查询字符串

ASP.NET - 母版页中的更新面板,内容页中的刷新按钮

Javascript 或其他使用语音阅读整个 HTML 页面的方法(离线)

javascript - 无需按钮即可动态更改JSP页面内容

asp.net - IIS7 和 Vista 上的 ASP .NET 2 的 URL 重写问题

mysql - 解析 web.config 时出现配置错误

asp.net - 在 TreeView asp.net 中使用复选框

delphi - 如何同步2个TTreeview的滚动?