3 回答

TA贡献1877条经验 获得超1个赞
<input type="text" value="Name:">
type
value
).
attributes
<input id="the-input" type="text" value="Name:">
id
,type
value
这个 id
属性是 反射性质为 id
属性:获取属性读取属性值,并设置属性写入属性值。 id
是 纯反射属性,它不修改或限制值。 这个 type
属性是 反射性质为 type
属性:获取属性读取属性值,并设置属性写入属性值。 type
不是纯反射属性,因为它仅限于 已知值(例如,输入的有效类型)。如果你有 <input type="foo">
,然后 theInput.getAttribute("type")
给你 "foo"
但 theInput.type
给你 "text"
.相反, value
属性不反映 value
属性。相反,这是 电流值输入。当用户手动更改输入框的值时, value
属性将反映此更改。所以如果用户输入 "John"
进入输入框,然后: theInput.value // returns "John"
鉴于: theInput.getAttribute('value') // returns "Name:"
这个 value
属性反映 电流输入框中的文本内容,而 value
属性包含 初始文本 value
属性来自HTML源代码。 因此,如果您想知道文本框中当前的内容,请阅读该属性。但是,如果您想知道文本框的初始值是什么,请读取属性。或者您可以使用 defaultValue
属性,它是 value
属性: theInput.value // returns "John"theInput.getAttribute('value') // returns "Name:"theInput.defaultValue // returns "Name:"
rel
, id
htmlFor
for
className
class
src
, href
, disabled
, multiple

TA贡献1890条经验 获得超9个赞
添加回答
举报