HTML DOM Input Range type 属性
htmlweb developmentfront end technology更新于 2025/10/16 22:04:17
HTML DOM Input Range type 属性与 type="range"的输入元素关联。它将始终返回输入范围元素的 range。
语法
以下是 Input Range type 属性的语法 −
rangeObject.type
示例
让我们看一个范围类型属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Input range type Property</h1>
<form>
VOLUME <input type="range" id="RANGE1" name="VOL">
</form>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="rangeType()">GET Type</button>
<p id="Sample"></p>
<script>
function rangeType() {
var P=document.getElementById("RANGE1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击 GET 类型方法 −

在上面的例子中 −
我们在表单中创建了一个输入字段,其类型为"range",id为"RANGE1",name为"VOL" −
<form> VOLUME <input type="range" id="RANGE1" name="VOL"> <form>
然后,我们创建了一个按钮"GET Type",当用户点击该按钮时,它将执行 rangeType() 方法 −
<button type="button" onclick="rangeType()">Get Type</button>
rangeType() 方法使用 getElementById() 方法获取输入元素,并将其 type 属性值赋给变量 P。然后,该变量将使用其 innerHTML 属性显示在 id 为"Sample"的段落中。 −
function rangeType() {
var P = document.getElementById(“RANGE1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

