阅读(1976) (0)

jQuery attributes和properties的区别

2017-07-21 17:37:21 更新

attributes 是 XML 结构中的属性节点概念范畴:

<body onload="prettyPrint()"></body>

上面的代码表示了 body 这个节点,有一个名为 onload 的 attributes 。

properties 则是对于 DOM 对象的,对象属性概念范畴。这一般就没有直观的表现,但是它总是可以被访问到的,比如:

$('body').get(0).tagName;
//BODY

虽然 attributes 与 properties 是不同的概念范畴,但是它们对于某些特殊的属性是有共同的访问属性名的,比如 id