Input Range defaultValue attribute
Definition and usage
defaultValue
Sets or returns the default value of the slider control.
Note:The default value is HTML value attribute as specified in
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).
The defaultValue attribute is very useful if you want to find out if the value of the slider control has changed.
Instance
Example 1
Get the default value of the slider control:
var x = document.getElementById("myRange").defaultValue;
Example 2
An example showing the difference between defaultValue and value attributes:
var x = document.getElementById("myRange"); var defaultVal = x.defaultValue; var currentVal = x.value;
Syntax
Return the defaultValue attribute:
rangeObject.defaultValue
Set the defaultValue attribute:
rangeObject.defaultValue = value
属性值
值 | 描述 |
---|---|
value | 指定滑块控件的默认值。 |
技术细节
返回值: | 字符串值,表示滑块控件的默认值。 |
---|
浏览器支持
表中的数字指出了首个完全支持该属性的浏览器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 10.0 | 支持 | 支持 | 支持 |