做了个实验:
<head runat="server">
    <title></title>
       <script>
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div id="d1" style="width:100px; height:10px;"></div>
    <input type="text" id="txt"/>
    <input type="button" onclick="alert(d1.style.height);"/>
  
    </form>
 
</body></html>这样的话,IE可以alert出元素高度,火狐不行.
然后把
<input type="button" onclick="alert(d1.style.height);"/>
改成
<input type="button" onclick="alert(txt.value);"/>
的话,两者都能显示输入框高度.是不是意味着对于输入表单,FF和IE都能直接通过ID访问,而对于非输入表单,FF必须通过getElementById访问,而IE依然可以直接通过ID访问呢?
请指教!~谢谢~~~

解决方案 »

  1.   

    兼容写法:document.getElementById
      

  2.   

    <input type="button" onclick="alert(d1.style.height);"/>
    FF不支持d1.style.....
    就像谷歌代码 大小写一样
     ajax的时候, 大小写出问题都不能运行,而且,谷歌直接屏蔽所有的js报错.
      

  3.   

    还是按规矩来吧,兼容性很重要 document.getElementById()
      

  4.   

    onclick="" 引号中要是的javascript脚本 
     <input type="button" onclick="alert(d1.style.height);"/>
     你这样直接写出来 浏览器不知道 你引号中是什么东东
    <input type="button" onclick="javascript:alert(d1.style.height);"/>
    这样子试试吧 
      

  5.   

    IE的做法本身就很变态.  IE6中偷懒的写法在IE9中一样被淘汰了.  document是棵树. 你必须要一级一级的去找.