Input Email defaultValue attribute
Definition and usage
defaultValue
Sets or returns the default value of the email field.
Note:The default value is HTML value attribute specified in the.
The difference between defaultValue and value attributes is:
- defaultValue contains the default value
- While value contains the current value after some changes
- If there is no change, defaultValue and value are the same (see the example below)
The defaultValue attribute is very useful if you want to find out if the email field has been changed.
Instance
Example 1
Change the default value of the email field:
document.getElementById("myEmail").defaultValue = "stevejobs@codew3c.com";
Example 2
Get the default value of the email field:
var x = document.getElementById("myEmail").defaultValue;
Example 3
An example showing the difference between defaultValue and value attributes:
var x = document.getElementById("myEmail"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return the defaultValue attribute:
emailObject.defaultValue
Set the defaultValue attribute:
emailObject.defaultValue = value
属性值
值 | 描述 |
---|---|
value | 规定电子邮件字段的默认值。 |
技术细节
返回值: | 字符串值,代表电子邮件字段的默认值。 |
---|
浏览器支持
表中的数字注明了首个完全支持该属性的浏览器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 10.0 | 支持 | 支持 | 支持 |