diff --git a/src/modules/lay.js b/src/modules/lay.js index 7ce3c1e8..f0c369d9 100644 --- a/src/modules/lay.js +++ b/src/modules/lay.js @@ -628,6 +628,7 @@ * @param {string} [options.event="pointerdown"] - 监听的事件类型 * @param {HTMLElement | Window} [options.scope=document] - 监听范围 * @param {Array} [options.ignore] - 忽略监听的元素或选择器字符串 + * @param {boolean} [options.capture=true] - 对内部事件侦听器使用捕获阶段 * @returns {() => void} - 返回一个停止事件监听的函数 */ lay.onClickOutside = function(target, handler, options){ @@ -635,6 +636,7 @@ var eventType = options.event || ('onpointerdown' in window ? 'pointerdown' : 'mousedown'); var scopeTarget = options.scope || document; var ignore = options.ignore || []; + var useCapture = 'capture' in options ? options.capture : true; var listener = function(event){ var el = target; @@ -692,14 +694,14 @@ } if(document.addEventListener){ - scopeTarget.addEventListener(eventType, listener, false); + scopeTarget.addEventListener(eventType, listener, useCapture); }else{ scopeTarget.attachEvent('on' + eventType, listener); } var stop = function(){ if(document.removeEventListener){ - scopeTarget.removeEventListener(eventType, listener, false); + scopeTarget.removeEventListener(eventType, listener, useCapture); }else{ scopeTarget.detachEvent('on' + eventType, listener); }