?
IE6/7/8(Q)中元素的attribute与property内部实现是不分的,IE8部分分离,IE9实现彻底分离了。
?
如下:
<div id="myId" class="cls" userAttribute="test1"> <script type="text/javascript"> var div = document.getElementById('myId'); div.userProperty = 'test2'; alert(div.attributes.length); // IE6/7/8 -> 4 , [id,class,userAttribute,userProperty] // IE9 -> 3, [id,class,userAttribute] alert(div.userAttribute); // IE6/7/8 -> 'test1' // IE9 -> undefined alert(div.getAttribute('userAttribute')); // IE6/7/8/9 -> 'test1' alert(div.getAttribute('userProperty')); // IE6/7/8 -> 'test2' // IE9 -> null </script>
?
注:Firefox/Safari/Chrome/Opera的表现同IE9。?
?
关于attribute和property的详细分析强烈推荐w3help网站,猛击:http://w3help.org/zh-cn/causes/SD9006
?
?
1 楼
cloudgamer
2010-09-08
其实在ie8中已经把attribute和property区分开了,但估计是为了兼容,并没有做彻底
例如getAttribute("innerHTML")返回的是null,说明innerHTML不再是attribute;setAttribute("class",x)修改的是attribute,不再是给dom元素添加一个莫名其妙的class属性
我在这里的attribute/property部分就研究过
例如getAttribute("innerHTML")返回的是null,说明innerHTML不再是attribute;setAttribute("class",x)修改的是attribute,不再是给dom元素添加一个莫名其妙的class属性
我在这里的attribute/property部分就研究过
2 楼
hite
2010-09-15
attribute和property的区别和
library 和framework一样困惑了好久!
property我觉得应该从“财产;性质,性能;所有权”来理解,它是成员,part of ,belong to的概念
attribute――“把…归于;归属”,也就是说以前不属于而现在属于的意思。
library 和framework就无解了,我完全不能区分,mootools是框架吗,jquery是库吗?
ps:刚刚看完上面两个链接,找到根。
“attribute是dom元素在文档中作为html标签拥有的属性,property就是dom元素在js中作为对象拥有的属性”
library 和framework一样困惑了好久!
property我觉得应该从“财产;性质,性能;所有权”来理解,它是成员,part of ,belong to的概念
attribute――“把…归于;归属”,也就是说以前不属于而现在属于的意思。
library 和framework就无解了,我完全不能区分,mootools是框架吗,jquery是库吗?
ps:刚刚看完上面两个链接,找到根。
“attribute是dom元素在文档中作为html标签拥有的属性,property就是dom元素在js中作为对象拥有的属性”
3 楼
LonelyStar
2010-09-15
又要写更多的兼容代码了。。。
4 楼
grandboy
2010-09-16
如上各位分析,那应该在IE8下运行的程序没有问题,在IE9下应该也没有问题了?