当前位置:编程学习 > C#/ASP.NET >>

设置树节点的展开和折叠出现奇怪错误 JS脚本错误提示EVENT为空或不是对象


var objtree = document.getElementById("TreeView1");
var node = objtree.getChildren(); 
if(node.getAttribute("Expanded")==true)
{
  node[0].setAttribute("Expanded", "true");
  执行成功
}
else
{
  node[0].setAttribute("Expanded", "true");
  执行失败  JS脚本错误提示EVENT为空或不是对象
} --------------------编程问答-------------------- node[0].setAttribute("Expanded", "true");
这句换成node[0].Expanded="true";试下 --------------------编程问答-------------------- 试过了 不行还是一样的
--------------------编程问答-------------------- var objtree = document.getElementById("TreeView1");
var node = objtree.getChildren(); 
if(node.getAttribute("Expanded")==true)
{
  node[0].setAttribute("Expanded", "true");
  执行成功
}
else
{
  node[0].setAttribute("Expanded", "true还是false");
  执行失败  JS脚本错误提示EVENT为空或不是对象
}  --------------------编程问答-------------------- 是True  这个时候node[0]的Expanded是false --------------------编程问答-------------------- 我是手动点击树节点折叠让它的Expanded为false  再执行展开时node[0].setAttribute("Expanded", "true"); JS脚本错误提示EVENT为空或不是对象
--------------------编程问答-------------------- 放完整的代码上来看看 --------------------编程问答-------------------- function findop(opflag ,pid, guid, company,易做图)
    {
    
        var objtree = window.parent.document.getElementById("TreeView1");
        var rootnode = objtree.getChildren(); 
        
        //遍历树
        findtree(objtree,rootnode[0],opflag,pid,guid, company,易做图);
    }
    function findtree(objtree,node,opflag ,pid, guid, company,易做图)
    { 
        var ChildNode = node.getChildren();
     
        var 易做图img="boy.gif";
        
        if(易做图==0) 
            易做图img="girl.gif";        
        //没有子节点
        if(ChildNode.length<1)
        {      
            if(opflag=="ins")//公司档案开发时的特殊代码
            {          
                if (node.getAttribute("NodeData").toUpperCase() == pid.toUpperCase())
                {
                    //在当前查找到的节点下:添加子节点
                    var nodeadd = objtree.createTreeNode();
                    var parentNode = objtree.getTreeNode(objtree.clickedNodeIndex);
                    node.add(nodeadd);                   
                    nodeadd.setAttribute("Text", company);
                    nodeadd.setAttribute("NodeData", guid);
                    nodeadd.setAttribute("Target", "doss");
                    nodeadd.setAttribute("NavigateUrl","employee.aspx?pid="+pid);
                    nodeadd.setAttribute("ImageUrl","../../Images/"+易做图img);
                    //parentNode.setAttribute("Expanded", "true");//展开父节点
//                    try
//                    {
                          node.setAttribute("Expanded", "true");//展开父节点                    
//                       //ExpandNode(node);
//                       var objtreeinnerHTML = window.parent.document.getElementById("TreeView1").innerHTML;
//        
//                        window.parent.document.getElementById("TreeView1").innerHTML = objtreeinnerHTML.replace(""+company+"<tvns:treenode Expanded=\"Flase\"",""+company+"<tvns:treenode Expanded=\"True\"");
//                    }
//                    catch(ex)
//                    {
//                        alert(ex.description);
//                    }
                    return;
                }
            }
        }
        
        //存在子节点
        for(var i=0;i<ChildNode.length;i++)
        {
            if(opflag=="ins")
            {
                if (node.getAttribute("NodeData").toUpperCase() == pid.toUpperCase())
                {
                    //在当前查找到的节点下:添加子节点
                    var nodeadd = objtree.createTreeNode();
                    var parentNode = objtree.getTreeNode(objtree.clickedNodeIndex);
                    node.add(nodeadd);
                    nodeadd.setAttribute("Text", company);
                    nodeadd.setAttribute("NodeData", guid);
                    nodeadd.setAttribute("Target", "doss");
                    nodeadd.setAttribute("NavigateUrl","employee.aspx?pid="+pid);
                    nodeadd.setAttribute("ImageUrl","../../Images/"+易做图img);
                    //parentNode.setAttribute("Expanded", "true");//展开父节点
                    try
                    {
                       if(node.getAttribute("Expanded"))
                       {
                         node.setAttribute("Expanded", "true");//展开父节点
                       }
                       else
                       {                   
                          //alert(parentNode.getAttribute("Text"));  
                          //alert(node.getAttribute("Text"));     
                          //node.setAttribute("Expanded", "true");//展开父节点
                          //var Expand=module_system_employee.Expanded_Node(node.getAttribute("NodeData"),true).value;
                          alert(parentNode.getAttribute("Expanded"));
                          parentNode.setAttribute("Expanded", "true");//展开父节点
                       }                                            
                    }
                    catch(ex)
                    {
                        alert(ex.description);
                    }
                    return;
                }
            }
            else if (ChildNode[i].getAttribute("NodeData").toUpperCase() == guid.toUpperCase())
            {
                if(opflag=="up")
                {
                    ChildNode[i].setAttribute("Text", company);
                    ChildNode[i].setAttribute("ImageUrl","../../Images/"+易做图img);
//                    try
//                    {
//                        ChildNode[i].setAttribute("Expanded", "true");//展开父节点
//                    }
//                    catch(ex)
//                    {
//                        alert(ex.description);
//                    }
                }
                else if(opflag=="del")
                {
                    try
                    {
                        ChildNode[i].remove();
                    }
                    catch(ex)
                    {
                        //alert(ex.description);
                    }
                }
                return;
            }
            findtree(objtree,ChildNode[i],opflag ,pid, guid, company,易做图);
        }
    } --------------------编程问答-------------------- 代码太多  要不远程调试一下 --------------------编程问答-------------------- 节点的数据都是数据库里的 --------------------编程问答-------------------- 1\findtree(objtree,rootnode[0],opflag,pid,guid, company,易做图);
为什么提交了objtree还要提交rootnode[0]?

你这个递归本身的问题,写得太乱了
--------------------编程问答--------------------     function ExpandedAll(Node, Expanded) {
        var ChildNode = Node.getChildren();
        for (var i = 0; i < ChildNode.length; i++) {
            ChildNode[0].getAttribute("Expanded", Expanded)
            if (ChildNode[i].getChildren().length > 0) {
                findtree(ChildNode[i], Expanded);
            }
        }
    }
    //展开
    var objtree = window.parent.document.getElementById("TreeView1");
    objtree.getAttribute("Expanded", true);
    ExpandedAll(objtree, true);

    //收缩
    var objtree = window.parent.document.getElementById("TreeView1");
    objtree.getAttribute("Expanded", false);
    ExpandedAll(objtree, false); --------------------编程问答-------------------- 我调试了 展不开 当Expanded为false的时候 还是没反应
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,