Jquery为什么toggleClass不在这里工作?

时间:2015-06-17 08:48:07

标签: javascript jquery

我正在使用此代码:

$(".heading.media").click(function (event) {
    $("#cart").toggleClass("active");
    $('#cart').load('index.php?route=module/cart #cart > *');
});

但由于某种原因,.toggleClass("active")无效。它打开但我不能在那之后切换。

当我删除$('#cart').load('index.php?route=module/cart #cart > *');时,它的工作正常。

为什么$('#cart').load('index.php?route=module/cart #cart > *');会造成麻烦?

1 个答案:

答案 0 :(得分:3)

尝试按event delegation方法选择元素并尝试。

$(document).on('click', '.heading.media', function (event) {
    $("#cart").toggleClass("active");
    $('#cart').load('index.php?route=module/cart #cart > *');
});