本文介绍了IE8 toggleClass无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我有一个菜单,我希望有一个叫做活跃的课程,当它活跃时,很明显。

Well I have a menu and there I want to have an class called active, when its active, obviously.

要切换此类我正在使用jQuery切换功能,但它只是在js元素中激活它。如果我检查dom元素,则从不设置此类。但是我需要这个类,因为我的CSS样式。

To toggle this class I am using the jQuery toggle function, but it does just activate it in the js element. If I check the dom element, this class is never set. But I need this class, because of my CSS styles.

我知道有很多关于 toggleClass 的主题jQuery,但它们不适合(至少我找不到合适的东西)

I know that there are already many topics about toggleClass jQuery, but they doesn't fit (at least I couldn't find anything suitable)

这里有一些代码:

$('#menu').on('click', '.tab span', function (e) {
    e.stopPropagation();
    var $tab = $(this).parent('.tab');
    $tab.siblings('.tab.active').removeClass('active');
    $tab.toggleClass('active');
});

HTML标记

<div id="menu">
    <div class="tab">
        <span></span>
    </div>
</div>

它适用于所有浏览器,IE8
除外提前付款。

Its working in all browsers, except IE8Thanks in advance.

推荐答案

请改为尝试:

$('#menu').on('click', '.tab span', function (e) {
    e.stopPropagation();
    var $tab = $(this).parent('.tab');
    $tab.addClass('active').siblings('.tab').removeClass('active');
});

这篇关于IE8 toggleClass无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 23:44