如题
系统有没有这样的函数..??不要自己写的
谢谢

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script type="text/javascript" language="javascript">
    function isParent(obj,pobj){
    do{
    obj = obj.parentNode;
    if(obj==pobj){
    return true;
    }
    }while(obj.tagName!='BODY');
    return false;
    }
    window.onload = function (){
    alert(isParent($("d1"),$("t1")));//true
    alert(isParent($("d1"),$("td1")));//false
    }
    function $(id){
    return document.getElementById(id);
    }
    </script>
    </head><body>
    <table id="t1">
    <tr>
    <td>
    <div id="d1"></div></td>
    <td id="td1"></td>
    </tr>
    </table>
    </body></html>
      

  2.   


    function contains(a, b){
      return a.contains ?
        a != b && a.contains(b) :
        !!(a.compareDocumentPosition(b) & 16);
    }解释请看这里http://ejohn.org/blog/comparing-document-position/
      

  3.   

    谢谢,不过我是要系统自带的函数... 像java 的 instanceof 一样
      

  4.   

    是我理解错了,我还以为说的是html元素...
      

  5.   

    var contains = (function(){
    if (document.documentElement.compareDocumentPosition) return function(nodeA, nodeB){
    return (nodeA.compareDocumentPosition(nodeB) & 16) == 16;
    }
    if (document.documentElement.contains) return function(nodeA, nodeB){
    return nodeA.contains(nodeB) && nodeA != nodeB;
    };
    return function(nodeA, nodeB){
    while (nodeB = nodeB.parentNode) 
    if (nodeB == nodeA) return true;
    return false;
    }
    })();