Input Month defaultValue attribute
Definition and usage
defaultValue
Property to set or return the default value of the month field.
Note:The default value is HTML value attribute specified in the following.
The difference between defaultValue and value properties is that 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 "More Examples").
The defaultValue property is very useful if you want to check if the month/year of the month field has changed.
Instance
Example 1
Change the default value of the month field:
document.getElementById("myMonth").defaultValue = "2023-06";
Example 2
Get the default value of the month field:
var x = document.getElementById("myMonth").defaultValue;
Example 3
An example showing the difference between defaultValue and value properties:
var x = document.getElementById("myMonth"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return defaultValue property:
monthObject.defaultValue
set defaultValue property:
monthObject.defaultValue = value
属性值
值 | 描述 |
---|---|
value | 规定月份字段的默认值。 |
技术细节
返回值: | 字符串值,表示月字段的默认值。 |
---|
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 10.0 | 支持 | 支持 | 支持 |
注意: 元素在 Firefox 中不显示任何日期字段/日历。