jQuery removeClass 无法处理弹出窗口
jQuery removeClass not working on popup
这是我的代码
jQuery('.woshadow').click(function(){
jQuery(this).find('.popup-list').addClass('popup-listh');
jQuery(this).find('.close-popup').addClass('popup-listh');
});
jQuery('.close-popup').click(function(){
jQuery(this).parent().find('.popup-list').removeClass('popup-listh');
jQuery(this).removeClass('popup-listh');
});
当我使用 addClass 而不是 removeClass 时,它很好并且可以正常工作,但是它不能与 removeClass 一起使用,这真的很罕见,请问有什么建议吗?
If you click on .close-popup, event propagate to .woshadow level, and
so re-add class
简单的解决方法是停止子元素上的事件传播:
jQuery('.close-popup').click(function(e){
e.stopPropagation();
jQuery(this).parent().find('.popup-list').removeClass('popup-listh');
jQuery(this).removeClass('popup-listh');
});
这是我的代码
jQuery('.woshadow').click(function(){
jQuery(this).find('.popup-list').addClass('popup-listh');
jQuery(this).find('.close-popup').addClass('popup-listh');
});
jQuery('.close-popup').click(function(){
jQuery(this).parent().find('.popup-list').removeClass('popup-listh');
jQuery(this).removeClass('popup-listh');
});
当我使用 addClass 而不是 removeClass 时,它很好并且可以正常工作,但是它不能与 removeClass 一起使用,这真的很罕见,请问有什么建议吗?
If you click on .close-popup, event propagate to .woshadow level, and so re-add class
简单的解决方法是停止子元素上的事件传播:
jQuery('.close-popup').click(function(e){
e.stopPropagation();
jQuery(this).parent().find('.popup-list').removeClass('popup-listh');
jQuery(this).removeClass('popup-listh');
});