开发者

jQuery - attribute vs. property [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

.prop() vs .attr()

Is there a difference between an attribute and a pr开发者_运维百科operty 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜