document.addEventListener('click', function (e) { if (document.getElementsByClassName('keywordContainer')[0]) { if (!document.getElementsByClassName('keywordContainer')[0].contains(e.target)) {//这句话是说如果我们点击到了class为keywordContainer以外的区域 app.isShowItem
1.给页面文档添加一个点击事件函数,在函数内实现隐藏菜单功能. $('html').click(function(){//Hide the menus if visible});//用$(document)也可以 2.对于菜单本身不希望在点击它时将自己隐藏,需要为菜单本身的点击事件添加以下方法,用来阻止点击事件的传播. //在所有不想触发页面点击事件的地方 阻止冒泡. $('#menucontainer').click(function(event){event.stopPropagation(