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

参考链接:
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 );

版权声明:本文为xiluoduyu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。