诀窍1:使用el.contains(e) 来判断点击的区域诀窍2:使用mouseup 诀窍3:完成之后,移除事件 showpopover (e) { this.popover = !this.popover var closePopover = (event) => { if (!this.$refs.popover.contains(event.target)) { this.popover = false document.body.removeEventListener('mouseup'…
什么是事件冒泡? 如图:在一个对象上触发某类事件(比如单击onclick事件),这个事件会向这个对象的父级对象传播,从里到外,直至它被处理(父级对象所有同类事件都将被激活),或者它到达了对象层次的最顶层,即document对象(有些浏览器是window).自下而上的去触发事件. 事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件. html结构 <div class="screen" id="parent"> <div c…
我们经常会出现点击空白处关闭弹出框或触发事件 <div class="aa" style="width: 200px;height: 200px;background-color: red;"></div> js代码 $(document).mouseup(function(e) { var _con = $('.aa'); // 设置目标区域 if (!_con.is(e.target) && _con.has(e.targ…
$(document).mousedown(function(e){ var _list = $('#pop'); if(!_list.is(e.target) && _list.has(e.target).length === 0){ $('#pop').hide(); } }); 判断点击事件发生在区域外的条件:1. 点击事件的对象不是目标区域本身2. 事件对象同时也不是目标区域的子元素…
<template> <div class="step2"> <el-button @click="togglePanel($event)">点击</el-button> <div class="shaw-box" v-if="visible" ref="main">弹出层</div> </div> </templat…
$(function(){ $(document).bind("click",function(e){ //id为menu的是菜单 if($(e.target).closest("#menu").length == 0 && $(e.target).closest("input").length == 0){ //点击id为menu之外且id,则触发 hideMenu(); } }) })…
原博主地址:http://www.cnblogs.com/godlovelian/p/4530342.html…
其实当用户在使用 PopUpManager 打开的某个组件外部单击时,会从该组件分派一个mouseDownOutside事件 监听该事件就能实现点击空白处关闭窗口的功能 this.addEventListener("mouseDownOutside",mouseDownOutside_Handler); private function mouseDownOutside_Handler(event:Event):void { PopUpManager.removePopUp(this)…
默认情况下点击空白处时会关闭模态框,添加data-backdrop="static"后可以阻止关闭…
在乐学一百的项目当中引用到了BootstrapDialog,其中后台发送短信时,为了防止管理员编辑了半天的短息,突然间因为点击某个空白区域导致丢失,所以在此禁用掉点击空白关闭弹出框. 主要属性为: closable: false, BootstrapDialog.show({ 2 title: '一键群发', 3 message: html, type: BootstrapDialog.TYPE_DEFAULT, closable: false, cssClass: 'dialog_mar',…