<script type="text/javascript">
var div = document.getElementById("div2");
alert(typeof div);//IE,FF->object
</script>

解决方案 »

  1.   

    非常感谢!当div2不存在时候怎么也返回object呢??
      

  2.   

    不存在的时候document.getElementById("div2")是null
    typeof null也是ojbect
    typeof "aa"也是string
    你可以这样:
    if(div!=null && type div=="object")
    {
        alert("is object");
    }
      

  3.   

    if(div!=null && typeof div=="object")
    {
        alert("is object");
    }
      

  4.   

    typeof返回以下几种undefined,string,number,boolean,object
      

  5.   

    typeof 这个东西的用法好奇怪 typeof后面不加();
     typeof(div); 也不报错~~ 呵呵