vue自己写了一个div菜单,点击按钮展开,点击其他地方关闭这个div菜单

2023-05-12,,

需求是通过点击body页面,在其他地方就关闭这个<div>菜单,给这个div一个id:problemList,但是点击我打开的按钮,不关闭。

created () {
document.onclick = function () {
  // 要关闭的div的id (problemList)
document.getElementById('problemList').style.display = 'none'
}
},

点击按钮打开模态框的方法要写个阻止冒泡事件,不然会点不开

getItme() 是点击打开div的事件

// 控制问题列表的显示和关闭
getItme (e, num) {
this.stopEvent(e)
document.getElementById('problemList').style.display = 'block'
},

  

vue自己写了一个div菜单,点击按钮展开,点击其他地方关闭这个div菜单的相关教程结束。

《vue自己写了一个div菜单,点击按钮展开,点击其他地方关闭这个div菜单.doc》

下载本文的Word格式文档,以方便收藏与打印。