我目前的用的是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”。