【问题标题】:jQuery SlideToggle() Not Working in FireFox, Works in ChromejQuery SlideToggle() 在 FireFox 中不工作,在 Chrome 中工作
【发布时间】:2012-08-05 00:44:28
【问题描述】:

我的代码是这样的:

jQuery('.cart-module .cart-heading').bind('click', function() {
    if (jQuery(this).hasClass('active')) {
        jQuery(this).removeClass('active');
    } else {
        jQuery(this).addClass('active');
    }

    jQuery(this).parent().find('.cart-content').slideToggle('slow');
});
//--></script> 

您可以通过快速将产品添加到您的购物车(如https://muddydogcoffee.com/teas/176-organic-crimson-berry-fruit-tisane?device=iphone)并在此处进入购物车https://muddydogcoffee.com/shopping-cart 来自行测试。

当您点击“预估运费和税费”时,它应该会在其下方显示 DIV。但是,它仅适用于 Chrome,不适用于 Firefox。我该怎么做才能解决这个问题?

谢谢。

【问题讨论】:

    标签: javascript jquery firefox google-chrome


    【解决方案1】:

    我之前也遇到过同样的问题,我还没有真正理解为什么会这样,但我找到了解决方法。

    我不确定它是否也适用于你,但我所做的是我删除了样式表中的 display:none 并将其添加到 html 中。

    如果有人能解释这种奇怪的行为,那真的很有帮助。

    【讨论】:

    • 你是个了不起的人!我很高兴为此找到解决方案。当然,我也想知道原因。非常感谢。
    【解决方案2】:

    添加 event.preventDefault(); 和 event.stopPropagation(); 以使其在包括 Firefox 在内的所有浏览器中都能正常工作。请参阅下面的片段:

    jQuery('.cart-module .cart-heading').bind('click', function(e) {
        e.preventDefault();
        e.stopPropagation();
        if (jQuery(this).hasClass('active')) {
            jQuery(this).removeClass('active');
        } else {
            jQuery(this).addClass('active');
        }
     jQuery(this).parent().find('.cart-content').slideToggle('slow');
    });
    

    【讨论】:

      【解决方案3】:

      你试过了吗:

      $(document).ready(function() {
         // put all your jQuery goodness in here.
       });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多