removeClass()未被应用

时间:2011-12-05 08:43:17

标签: jquery

在我的jQuery代码中,removeClass无效。每当我点击hide链接时,IE6.0中的.close元素都没有删除,但它在firefox和IE8.0中有效,下面是我的jQuery代码:

$(document.ready(function()){
    toggleNodes = function(node,action){
        var $componentone = $('.componentone', node);

        if (action == undefined || action == 'hide'))) {
            $componentone.addClass('closed');
            $componentone.hide();
        }
        else if  (action=='undefined'||action=='view'){
            $componentone.removeClass('closed');
            $componentone.show();
        }
    }
});

`close'在.css文件中声明如下:

.componentone{
    margin-left:10px;
    padding-left:15px;
    border:1px solid #fff;
    border:0px solid #ddd;
}

.componentone.closed{
    margin-left:10px;
    padding-left:15px;
    border:1px solid #fff;
    border:0px solid #ddd; 
}

在JSP中我使用过它:

<div="componentone">body of div</div>
<div="component">body of div new</div>

1 个答案:

答案 0 :(得分:2)

你的其他条件有语法错误

else if { (action=='undefined'||action=='view')

        $info.removeClass('closed');
        $componentone.show();
       }

to

else if  (action=='undefined'||action=='view'){

        $info.removeClass('closed');
        $componentone.show();
       }