思路
彈框最外層套個id,監聽文檔點擊事件,循環查找父級id,判斷是否包含在外層id中,包含不處理,不包含彈窗關閉
注意點
具體問題具體分析,如html層級解構混亂時,需加入額外判斷來處理,但整體思想不變
例子,vue中使用
document.addEventListener("click", e => {
if (!this.overMark && this.showArrow) {
let el = e.target;
while (el) {
if (el.id == "menu-box") {
return;
}
el = el.parentNode;
}
this.showArrow = false;
}
});