Input Week defaultValue attribute
Definition and usage
defaultValue
Set or return the default value of the week field attribute.
Note:The default value is HTML value attribute specified in the following.
The difference between defaultValue and value attributes 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 the example below).
If you want to check if the week in the week field has changed, the defaultValue attribute is very useful.
Instance
Example 1
Change the default value of the week field:
document.getElementById("myWeek").defaultValue = "2023-W01";
Example 2
Get the default value of the week field:
var x = document.getElementById("myWeek").defaultValue;
Example 3
Show the example of the difference between defaultValue and value attributes:
var x = document.getElementById("myWeek"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return the defaultValue attribute:
weekObject.defaultValue
Set the defaultValue attribute:
weekObject.defaultValue = value
属性值
值 | 描述 |
---|---|
value | 规定星期字段的默认值。 |
技术细节
返回值: | 字符串值,表示星期字段的默认值。 |
---|
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 10.0 | 支持 | 支持 | 支持 |
注意:<input type="week"> 元素在 Firefox 中不显示任何日期字段/日历。