我正在使用此代码:
$(".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 > *');
会造成麻烦?
最佳答案
尝试通过 event delegation 选择元素方法并尝试。
$(document).on('click', '.heading.media', function (event) {
$("#cart").toggleClass("active");
$('#cart').load('index.php?route=module/cart #cart > *');
});
关于javascript - Jquery 为什么toggleClass 在这里不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30886623/