如何取得一个对象的类型?例如,
var w=window.open("...");
alert(getobjecttype(w));function getobjecttype(obj){
   return "window";            //如何得知w 是 window 还是 document 还是 div 还是 input
}

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript">
           function showType(obj){
                alert(obj.tagName);
           }
           window.onload=function(){
            showType(document.getElementById("A"));
            showType(document.body);
            showType(document.getElementById("Text1"));
           }
        </script>
    </head>
    <body>
    <span id="A"></span>
    <input id="Text1" type="text" />
    </body>
    </html>
      

  2.   

    window 还是 document 还是 div 还是 input
    以上4个属于不同范畴的层次
    window document是实例化的对象
    div input 根据lz上下文是指某种类型
      

  3.   

    完全解决方法by theforever_csdn
    <script type="text/javascript">
    function showType(obj){
    if(obj === window){alert('window');return;}
    if(obj === document){alert('document');return;}
    alert(obj.tagName);
    }
    window.onload=function(){
    showType(window);
    showType(document);
    showType(document.body);
    showType(document.getElementById("theforever_csdn"));
    }
    </script>
    <div id="theforever_csdn">div</div>
      

  4.   

    上面的确是一个有针对性的解决办法。
    但是,我想要一个通用的解决办法, 就是如何判断传入的object实例化前的原型