使用jQuery show()显示隐藏的divs元素在IE7中不起作用

时间:2011-02-14 16:28:38

标签: javascript jquery css internet-explorer-7

我正在尝试使用JavaScript创建树视图。我有一个动态创建的Div列表。显示的父节点和将不显示的子节点。当您点击父节点上的按钮时,它将调用show('slow')。这适用于IE8和IE9,但是当我用IE7测试它时,子节点将显示它的CSS类。如何使用IE7进行此操作?

主页中的代码

function CreateEventCategoryDiv(EventCategoryName) {
            var NewEventCategoryNode = document.createElement('div');
            NewEventCategoryNode.id = EventCategoryName + "Node";
            if (TreeNodeCounter == 0 || (TreeNodeCounter % 2) == 0) {
                NewEventCategoryNode.className = "EventCategoryNodesEven";
            }
            else {
                NewEventCategoryNode.className = "EventCategoryNodesOdd";
            }
            NewEventCategoryNode.innerHTML = "<input type='button' value='+' id='ExpandButton' class='ExpandNodeButtons' onclick='ExpandNode(\"" + EventCategoryName + "\");' />&nbsp;" + EventCategoryName;
            var EventTree = document.getElementById("EventTree");
            EventTree.appendChild(NewEventCategoryNode);
            TreeNodeCounter++;
        }

     function ExpandNode(PassedNode) {
                var ParentNode = CalendarObject.SearchCategoryNode(PassedNode);
                if (ParentNode.IsChildrenShowing == false) {
                    ParentNode.ExpandNodes(CalendarObject.Months);
                }
                else if (ParentNode.IsChildrenShowing == true) {
                    ParentNode.CollapseNode(CalendarObject.Months);
                }
            }

在EventCategory类中调用此部分来添加子节点(抱歉,我最初忘记了这个节点)

this.AddEventType = function (EventTypeNode) {
        var NewElement = document.createElement('Div');
        NewElement.id = EventTypeNode.DivAssociateId;
        NewElement.innerText = EventTypeNode.Name;
        if (this.NodesCount == 0 || (this.NodesCount % 2) == 0) {
            NewElement.setAttribute("class", "EventTypeNodesEven");
        }
        else {
            NewElement.setAttribute("class", "EventTypeNodesOdd");
        }
        NodesCount = this.EventTypeNodesArray.push(EventTypeNode);
        $(NewElement).hide();
        var ParentElement = document.getElementById("EventTree");
        ParentElement.appendChild(NewElement);
        this.NodesCount++;
    };

此部分位于CalendarGrid类

this.ExpandNodes = function (MonthArray) {
        for (var x in this.EventTypeNodesArray) {
            var SelectedNode = document.getElementById(this.EventTypeNodesArray[x].DivAssociateId);
            if (this.IsChildrenShowing == false) {
                $(SelectedNode).show('slow');
                for (var y = 0; y < MonthArray.length; y++) {
                    var SelectedRow = document.getElementById(this.EventTypeNodesArray[x].Name + MonthArray[y].MonthName + "Row");
                    $(SelectedRow).show('slow');
                }
            }
        }
        this.IsChildrenShowing = true;
    };

CSS代码:

.EventTypeNodesOdd
{
    font-family:Arial;
    font-weight:bold;
    text-align:center;
    height:27px;
    background-color:#dbe2e6;
    display:block;
}

.EventTypeNodesEven
{
    font-family:Arial;
    font-weight:bold;
    text-align:center;
    height:27px;
    background-color:#f9fafb;
}

1 个答案:

答案 0 :(得分:1)

尝试将类设置为显示后的任何内容。