.parentNode
如果我通过of递归event.target
,我能保证到达this
吗?规范中的任何地方都提到了这一点吗?
这是一些代码来演示这一点,它将记录 ifevent.target
是this
http://jsfiddle.net/Dogbert/aRLrG/
var isADescendentOf = function (child, parent) {
if (child === parent) {
return true;
}
if (child === null) {
return false;
}
return isADescendentOf(child.parentNode, parent);
};
var nodes = document.querySelectorAll("*");
for (var i = 0; i < nodes.length; i++) {
nodes[i].addEventListener("click", function (event) {
console.log(isADescendentOf(event.target, this));
});
}
HTML
<div id="a">A
<div id="b">B
<div id="c">C
<div id="d">D
<div id="e">E</div> <span id="f">F</span>
<button>B</button> <span>1<span>2<span>3
</span></span>
</span>
</div>
</div>
</div>
</div>