HTML DOM 輸入範圍 type 屬性
HTML DOM 輸入範圍 type 屬性與型別為“range”的 input 元素相關聯。它將始終返回輸入範圍元素的範圍。
語法
以下是 range 型別屬性的語法 −
rangeObject.type
例項
讓我們看一個 range 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 Type 方法 −

在上面的示例中 −
我們建立了一個表單中的輸入欄位,型別為“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;
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP