[英]Jquery Why doesn't toggleClass work here?
I'm using this code: 我正在使用此代码:
$(".heading.media").click(function (event) {
$("#cart").toggleClass("active");
$('#cart').load('index.php?route=module/cart #cart > *');
});
But for some reason the .toggleClass("active")
isn't working. 但是由于某种原因,
.toggleClass("active")
无法正常工作。 It opens but I can't toggle after that. 它会打开,但此后我无法切换。
When I remove $('#cart').load('index.php?route=module/cart #cart > *');
当我删除
$('#cart').load('index.php?route=module/cart #cart > *');
it works just fine. 它工作正常。
Why does $('#cart').load('index.php?route=module/cart #cart > *');
为什么
$('#cart').load('index.php?route=module/cart #cart > *');
cause trouble ? 引起麻烦 ?
Try selecting the element by event delegation method and try. 尝试通过事件委托方法选择元素,然后尝试。
$(document).on('click', '.heading.media', function (event) {
$("#cart").toggleClass("active");
$('#cart').load('index.php?route=module/cart #cart > *');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.