关于 ie getAttribute() 的实现bug
来源:互联网 发布:电影院票房数据 编辑:程序博客网 时间:2024/05/17 23:44
在写通过元素 class 属性的时候遇到的 ie6、ie7在处理 getAttribute() 时与firefox 和 chrome的区别
<div><p></p><p></p><div><h3 class="items"></h3><p></p><p class="item" title="p元素" id="pi"></p><p></p><p></p></div><div><form><p></p></form></div></div>
js代码如下
<script type="text/javascript">function getElementByClass(name){var element = document.body.getElementsByTagName('*');var i=j=0;var arr= new Array();for(i=0;i<element.length; i++){//document.write(element[i].className + ' ');document.write(element[i].getAttribute('class') + " ");if(element[i].getAttribute('class') == name){arr[j] = element[i].nodeName;}}return arr;}var p='item';var str = getElementByClass(p);alert(str);</script>在使用getAttribute('class')时,在firefox 、chrome 、safari中都可一的到正确的结果,即可以的到 p 元素,但是ie6 、 ie7 不能得到class属性的值。ie8修复了这个bug,可以使用getAttribute('class')得到正确的结果。把getAttribute('class')改为 getAttribute('className')时在ie6 、ie7 下可以显示正确,但是在firefox 、chrome 、safari中不正确。当我用//document.write(element[i].className + ' ');时可一在以上浏览器中正确显示。所以我认为为了减少浏览器差异给编程带来影响,使用element[i].className ,即属性的方式更好。
- 关于 ie getAttribute() 的实现bug
- 关于IE的各种bug
- 关于IE的BUG(CSS)
- 关于IE下Ajax请求的BUG
- ie关于居中显示的bug
- 收集一些关于IE的BUG
- 一个关于ie的bug——双边距bug。
- 关于ie 11/edge浏览器在rem下的bug
- IE 的 BUG
- IE的bug
- ie bug的来源
- 可恶的IE bug
- IE浏览器的bug
- 关于使用js的setAttribute和getAttribute取dom属性在ie ff safri下的问题
- getAttribute的返回值类型(Firefox与IE兼容性)
- 关于 getAttribute 和 getParameter 的区别
- 常见IE浏览器的bug
- ie下人为的bug。
- Ogre1.7.2 + CEGUI0.7.5配置
- 代码中的命名规范及原则
- ASP.Net中控件的EnableViewState属性
- java学习路线
- Xdebug与PHPUnit
- 关于 ie getAttribute() 的实现bug
- iphone app中读取本地txt,csv文件 转载
- linux下删除当前文件夹中按时间排序的前N个文件夹
- 《开往天堂的列车》--肖玄 【为7.23特大高铁事故逝去的人们祈福!】
- poj 2828 Buy Tickets
- C#核心概念--装箱和拆箱(什么是装箱和拆箱)
- STMS传输问题
- 移除项目中VSS管理的链接(已解决)
- [转载]为UIView添加上下左右滑动操作(切换时)