#DOM中Property与Attribute的区别javascript
property和attribute的汉语翻译几乎相同,都有“属性”的意义(这里姑且称attribute为“特性”,以方便区分),而他们的取值也常常相同,但有时又会踩坑,发现两者会不相等,不一样步。如下文章总结一下它俩的特性和区别。更详情的对比,请看参考文章:DOM中Property与Attribute的区别java
##简述web
Property就是这些,至关于jQuery.prop():dom
dom.checked = false; dom.id = "footer"; $dom.prop("checked", false)
attribute就是这些,至关于jQuery.attr():spa
dom.setAttribute("href", "/download/"); dom.getAttribute("id"); $dom.attr("href", "/download/")
##差别翻译
.
读写dom的属性;attr经过setAttribute和getAttribute方法##同步与不一样步code
##其余ip
dom.setAttribute("a space", 100);
href
属性,prop与attr同步而不一样值,如// 对于<a href="/test/">link</a> a.getAttribute("href")// => /test/ a.href // => http://www.example.com/test/