attribute vs. property

Possible Duplicate:
.prop() vs .attr()

Is there a difference between an attribute and a property in the jQuery terminology? Is there an example that can clarify this point?


Is there a difference between an attribute and a property in the jQuery terminology?

Yes, there is a difference.

For example...

<input type="text" name="age" value="25" />

jsFiddle.

The attribute would be the value attribute as in the markup. You would use attr('value') .

The property would be the value property as accessed via the DOM API. You would use prop('value') (strictly speaking, you'd use val() ).

Sometimes they can be very similar, but not always.

链接地址: http://www.djcxy.com/p/27534.html

上一篇: jquery tr点击输入收音机检查

下一篇: 属性与财产