IE真是不可思議

     我目前的用的是IE8。也是在IE8裏測試兼容性的。一路寫過來,真想殺人了。

     我快崩潰了。前一陣子因爲IE下document.getElementsByClassName不支持,搞得我就夠鬱悶的。換了好多曲線方案,裁掉一些功能。才勉強開發下去。

     目前,我用document.getElementsByName,先測試瀏覽器支不支持,我滿心歡喜各大瀏覽器都支持了。結果FF始終如意,在IE下總是那麼彆扭。我之後寫了個頁面來專門測試IE下的getElimentsByName。如下,結果IE,兩個elements指向第一個div,FF下則指向各自的elements。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script type="text/javascript">
    function test(){
        alert(document.getElementById("test"));
        alert(document.getElementsByName("test").item(0));
    }
</script>
</head>
<body>
    <div id = "test"></div>
    <textarea name = "test"></textarea>
    <input type="button" value="test" onclick="test()"/>
</body>
</html>

 

關於IE下getElementsByName的這個bug在我代碼裏的解決方案,是索引值“+1”。
 

 

           

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章