更新时间:2023-02-13 18:31:59
技巧是检查单击的元素是否具有父.responsive-menu
或.menu-btn
.
The trick is to check if the element clicked has a parent .responsive-menu
or .menu-btn
.
如果两者都不存在且菜单已展开,请切换!
If it has'n any of the two and the menu is expanded, toggle!
$(document).on("click", function(e){
if(
$(e.target).closest(".responsive-menu").length == 0 &&
$(".responsive-menu").hasClass("expand") &&
$(e.target).closest(".menu-btn").length == 0
){
$('.responsive-menu').toggleClass('expand');
}
});