HTML DOM Input 重置按鈕 disabled 屬性
HTML DOM Input 重置按鈕的 disabled 屬性用於設定或返回重置按鈕是否應停用。它使用布林值,true 表示重置按鈕應停用,false 表示不停用。預設情況下,disabled 屬性設定為 false。停用的元素預設情況下顯示為灰色且不可點選。
語法
以下是語法:
設定 disabled 屬性:
resetObject.autofocus = true|false
這裡,true = 重置按鈕被停用,false = 重置按鈕未被停用。預設情況下為 false。
示例
讓我們來看一個 Input 重置按鈕 disabled 屬性的示例:
<!DOCTYPE html>
<html>
<body>
<h1>Input reset disabled Property</h1>
<form style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>
<p>Disable the above reset button by clicking on the DISABLE button</p>
<button type="button" onclick="disableReset()">DISABLE</button>
<p id="Sample"></p>
<script>
function disableReset() {
document.getElementById("RESET1").disabled=true;
document.getElementById("Sample").innerHTML = "The reset button is now disabled" ;
}
</script>
</body>
</html>輸出
這將產生以下輸出:

點選“停用”按鈕後:

在上面的例子中:
我們建立了一個 type="reset",id="RESET1" 的 <input> 元素。點選此按鈕將重置表單資料。此按鈕位於包含兩個文字欄位的表單內,表單還應用了內聯樣式:
<form style="border:solid 2px green;padding:2px"> UserName: <input type="text" id="USR"> <br> Location: <input type="text" id="Age"> <br><br> <input type="reset" id="RESET1"> </form>
然後,我們建立了一個名為“停用”的按鈕,當用戶點選它時,將執行 disableReset() 方法:
<button type="button" onclick="disableReset()">DISABLE</button>
disableReset() 方法使用 getElementById() 方法獲取 type 為 reset 的 input 元素,並將其 disabled 屬性設定為 true。這使得重置按鈕不可點選,使用者無法再與之互動。它現在變成了灰色:
function disableReset() {
document.getElementById("RESET1").disabled=true;
document.getElementById("Sample").innerHTML = "The reset button is now disabled" ;
}
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP