HTML - 属性与属性 [英] HTML - attributes vs properties
问题描述
id
HTML属性或属性 我应该如何做 $ ('#selector')。attr('id');
或 $('#selector')。prop('id');
我读过很多文章,但仍然感到困惑。
有人可以向我解释什么是差异属性和属性之间HTML / JS中的属性使用的语言非常简单?
属性由HTML定义。属性由DOM定义。
有些HTML属性映射到属性上有1:1。 id
就是这样一个例子。
有些不会(例如值
属性指定了输入的初始值,但是
值
属性指定了当前值。)
Is id
an attribute or property of HTML?
should I do $('#selector').attr('id');
or $('#selector').prop('id');
I've read many articles and am still confused.
Could someone please explain to me what the differences between attributes & properties in HTML/JS are in very simple language?
Attributes are defined by HTML. Properties are defined by DOM.
Some HTML attributes have 1:1 mapping onto properties. id
is one example of such.
Some do not (e.g. the value
attribute specifies the initial value of an input, but the value
property specifies the current value).
这篇关于HTML - 属性与属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!