2012-08-07 55 views
5

我的代码是这样的:的jQuery的slideToggle()在FireFox不工作,工作在Chrome

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。我能做些什么来解决这个问题?

谢谢。

回答

3

我以前有同样的问题,我还没有真正理解为什么它会发生,但我发现了一个解决方法吧。

我不确定它是否也适用于您,但我所做的是删除了样式表中的display:none,并且只是在html中添加了内联。

如果任何人都可以解释这种奇怪的行为,但它确实会有所帮助。

+0

你真棒!我很高兴为此找到解决方案。当然,我也想知道原因。非常感谢。 – user1477388 2012-08-08 00:45:56

0

你试过

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

我只是去尝试和,不,这是行不通的。 – user1477388 2012-08-08 00:12:00

+0

PS我没有downvote你的文章 – user1477388 2013-10-25 17:47:14

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'); 
}); 
相关问题