你去w3c的浏览器,如ff中就不会执行了,document.all只有ie能识别.

解决方案 »

  1.   

    if(document.all)用于判断是否是ie浏览器
    另外 if(null) 条件不成立 if(Object())条件成立, 可用if(document.getElementById('xx'))判断对象是否存在
      

  2.   

    只要条件是有意义的就执行if
    if(1)alert(1)
    if(2)alert(2)
    if(new Date())alert(d)
    if(null)alert(0)
    if(undefined)alert(0)
    if(0)alert(0)
    if(false)alert(0)
    if(true)alert(true)
    o = {}
    if(o)alert(o);
    o = []
    if(o)alert(o);
    if(document)alert(document)
    .
    .
    .
    等等...测试一下,你会发现没有alert出0,其他都会alert
      

  3.   

    这个是判断浏览器的,document.all只为IE支持,因此在做跨浏览器时,可能需要有针对性的写不同代码,这是就用你发的那段if来进行区分!
      

  4.   

    一句话js是弱类型语言
    只要变量不是null或者undefined,那么它都是真
      

  5.   

    如果一个对象的属性不存在,在javascript中,就将会翻译成undefined,在逻辑片段中undefined就会被认为是false...在非IE的浏览器中就会出现这个情况...