判断是否是点击在指定dom内部的方法

xiaoxiao2021-02-27  477

参考链接: http://stackoverflow.com/questions/26195091/determine-event-path-in-dom-event-bubbling

If event’s target attribute value is participating in a tree, let event path be a static ordered list of all its ancestors in tree order, and let event path be the empty list otherwise.

var red = document.getElementById( "red" ), green = document.getElementById( "green" ), msg = document.querySelector( "p" ); red.addEventListener( "click", function( evt ) { msg.textContent = "'" + evt.target.id + "' got poked, and 'green' was" + // access to the event path ( ~evt.path.indexOf( green ) ? "" : "n't" ) + " in the path."; }, false );
转载请注明原文地址: https://www.6miu.com/read-2554.html

最新回复(0)