zoukankan      html  css  js  c++  java
  • Javascript得到TreeView被选中的所有节点ID

            function GetCheckedNode()
            
    {
                
    var treeView=document.getElementById('<%= treeViewSource.ClientID %>');
                
    var children=treeView.getChildren();
                
    var checkedIds=GetCheckedNodeIds(children[0]);
                
    return checkedIds.substr(1,checkedIds.length);
            }

            
            
    function GetCheckedNodeIds(node)
            
    {
                
    var ids='';
                
    if(node.getAttribute("checked")==true)
                
    {
                    ids
    +=','+node.getAttribute("ID");
                }

                
    else
                
    {
                    
    var childNodes=node.getChildren();
                    
    var childCount=childNodes.length;
                    
    if(childNodes.length>0)
                    
    {
                        
    for(var i=0;i<childCount;i++)
                        
    {
                            ids
    +=GetCheckedNodeIds(childNodes[i]);
                        }

                    }

                }

                
    return ids;
            }
    注:treeViewSource是TreeView控件。
    被选中的意思是节点前的CheckBox被选中(checked)
    若当前节点被选中,则不遍历其子节点。
    最终返回选中节点ID用逗号分隔的字符串。
  • 相关阅读:
    使用Powershell开机启动隐藏窗口的程序
    使用鼠标左键事件实现VR中的Eye Gaze Input
    在github网站上更新fork的repo
    零Web知识个性化Blog
    C#中的Attribute
    ConsoleWindow中的双击日志定位
    Hackintosh Issues 10.13.x
    开启macOS的原生写入Ntfs的功能
    Install macOS High Sierra on Any Supported Intel-based PC
    DSDT/SSDT
  • 原文地址:https://www.cnblogs.com/brawei/p/1218083.html
Copyright © 2011-2022 走看看