<body>
<div?id="p-node">
<div?id="c-node">子節(jié)點內(nèi)容</div>
</div>
<script>
function?fixContains(a,?b)?{
????try?{
????????while?((b?=?b.parentNode)){
????????????if?(b?===?a){
????????????????return?true;
????????????}
????????}
????????return?false;
????}?catch?(e)?{
????????return?false;
????}
}
var?pNode?=?document.getElementById("p-node");
var?cNode?=?document.getElementById("c-node").childNodes[0];
alert(fixContains(pNode,?cNode));
//alert(fixContains(document,?cNode));
</script>
</body>
b=cNode.parentNode獲得的是里面的div,而a=pNode是外面的div,他們兩個怎么用===判定為true呢?
GYOUNY
2016-07-11 18:54:49