attribute 和 property的区别()-其他
attribute 和 property的区别()
一、针对对象不同
attribute 是针对 HTML 元素的,property 是针对DOM 节点的。
自定义属性只能是attribute,比如
<div boss="he" class="blue"> boss 是一个自定义属性</div>
二、读取和赋值不同
1, attribute 通过 getAttribute() 和 setAttribute()
比如:var boss = div.getAttribute(‘boss’)
2, property 则是常见的对象读写方式
比如:var blue = div.className
————————
一、针对对象不同
attribute 是针对 HTML 元素的,property 是针对DOM 节点的。
自定义属性只能是attribute,比如
<div boss="he" class="blue"> boss 是一个自定义属性</div>
二、读取和赋值不同
1, attribute 通过 getAttribute() 和 setAttribute()
比如:var boss = div.getAttribute(‘boss’)
2, property 则是常见的对象读写方式
比如:var blue = div.className