- HTML 教程
- HTML - 首頁
- HTML - 路線圖
- HTML - 簡介
- HTML - 歷史與演變
- HTML - 編輯器
- HTML - 基本標籤
- HTML - 元素
- HTML - 屬性
- HTML - 標題
- HTML - 段落
- HTML - 字型
- HTML - 塊
- HTML - 樣式表
- HTML - 格式化
- HTML - 引用
- HTML - 註釋
- HTML - 顏色
- HTML - 圖片
- HTML - 圖片地圖
- HTML - 內嵌框架 (Iframe)
- HTML - 短語元素
- HTML - 元標籤
- HTML - 類
- HTML - ID
- HTML - 背景
- HTML 表格
- HTML - 表格
- HTML - 表頭和標題
- HTML - 表格樣式
- HTML - 表格列組 (Colgroup)
- HTML - 巢狀表格
- HTML 列表
- HTML - 列表
- HTML - 無序列表
- HTML - 有序列表
- HTML - 定義列表
- HTML 連結
- HTML - 文字連結
- HTML - 圖片連結
- HTML - 郵件連結
- HTML 顏色名稱和值
- HTML - 顏色名稱
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML 表單
- HTML - 表單
- HTML - 表單屬性
- HTML - 表單控制元件
- HTML - 輸入屬性
- HTML 多媒體
- HTML - 影片元素
- HTML - 音訊元素
- HTML - 嵌入多媒體
- HTML 頭部
- HTML - head 元素
- HTML - 新增 Favicon
- HTML - Javascript
- HTML 佈局
- HTML - 佈局
- HTML - 佈局元素
- HTML - 使用 CSS 進行佈局
- HTML - 響應式設計
- HTML - 符號
- HTML - 表情符號
- HTML - 樣式指南
- HTML 圖形
- HTML - SVG
- HTML - Canvas
- HTML API
- HTML - Geolocation API
- HTML - 拖放 API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web 儲存
- HTML - 伺服器傳送事件
- HTML 其他
- HTML - 文件物件模型 (DOM)
- HTML - MathML
- HTML - 微資料
- HTML - IndexedDB
- HTML - Web 訊息傳遞
- HTML - Web CORS
- HTML - WebRTC
- HTML 演示
- HTML - 音訊播放器
- HTML - 影片播放器
- HTML - 網頁幻燈片
- HTML 工具
- HTML - Velocity Draw
- HTML - 二維碼
- HTML - Modernizer
- HTML - 驗證
- HTML - 顏色拾取器
- HTML 參考
- HTML - 速查表
- HTML - 標籤參考
- HTML - 屬性參考
- HTML - 事件參考
- HTML - 字型參考
- HTML - ASCII 碼
- ASCII 表格查詢
- HTML - 顏色名稱
- HTML - 實體
- MIME 媒體型別
- HTML - URL 編碼
- 語言 ISO 程式碼
- HTML - 字元編碼
- HTML - 已棄用的標籤
- HTML 資源
- HTML - 快速指南
- HTML - 有用資源
- HTML - 顏色程式碼生成器
- HTML - 線上編輯器
HTML - disabled 屬性
HTML disabled 是一個布林屬性,可以應用於各種表單元素,使它們無法互動或無法編輯。
當元素被停用時,使用者無法對其進行聚焦、點選或更改,並且它不會包含在表單提交中。它可以用於以下元素:<input>、<fieldset>、<button>、<textarea>、<select>、<option> 和 <optgroup> 等。
語法
<tag disabled>
應用於
以下列出的元素允許使用 HTML disabled 屬性。
| 元素 | 描述 |
|---|---|
| <input> | HTML <input> 標籤用於指定輸入欄位。 |
| <textarea> | HTML <textarea> 標籤用於表示多行純文字編輯控制元件。 |
| <button> | HTML <button> 標籤用於嵌入可點選按鈕。 |
| <fieldset> | HTML <fieldset> 標籤用於在一個 Web 表單中對多個控制元件和標籤進行分組。 |
| <select> | HTML <select> 標籤用於建立下拉列表以選擇專案。 |
| <option> | HTML <option> 標籤用於命名下拉列表中的專案。 |
| <optgroup> | HTML <optgroup> 用於在 select 元素中將相關的 option 元素組合在一起。 |
HTML disabled 屬性示例
下面的示例將說明 HTML disabled 屬性的用法,以及我們應該在哪裡以及如何使用此屬性!
停用 input 元素
在以下示例中,我們將使用 disabled 屬性和 input 欄位。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML disabled attribute</title>
</head>
<body>
<!--example of the 'disabled' attribute-->
<p>'disabled' attribute with input element.</p>
Text(disabled):
<input type="text"
placeholder="Disabled"
disabled>
<input type="text"
placeholder="Not disabled">
</body>
</html>
停用 button 元素
考慮另一種情況,我們將使用 disabled 屬性和 button 元素。
<!DOCTYPE html> <html lang="en"> <head> <title>HTML disabled attribute</title> </head> <body> <!--example of the 'disabled' attribute--> <p>'disabled' attribute with button element.</p> <button disabled>Disabled</button> <button>Not Disabled</button> </body> </html>
停用 fieldset 元素
讓我們看看下面的示例,我們將使用 disabled 屬性和 fieldset 元素。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML disabled attribute</title>
</head>
<body>
<!--example of the 'disabled' attribute-->
<p>'disabled' attribute with fieldset element.</p>
<fieldset disabled>
<legend>Login Form</legend>
Username:
<input type="text"
placeholder="username">
<br>
Password:
<input type="password"
placeholder="password">
<br>
<button>Login</button>
</fieldset>
</body>
</html>
停用 select 元素
在這個例子中,我們將使用 disable 屬性停用整個 select 標籤。
<!DOCTYPE html>
<html>
<body>
<h1>Disabled Select Element</h1>
<form action="html/index.htm">
<label for="fruits">Choose a fruit:</label>
<select id="fruits" name="fruits" disabled>
<option value="orange">Orange</option>
<option value="lemon">Lemon</option>
<option value="mango">Mango</option>
<option value="pineapple">Pineapple</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
停用下拉選單中的 optgroup
在這個例子中,我們將使用 disabled 屬性停用 select 下拉選單中的一組選項。
<!DOCTYPE html>
<html>
<body>
<h1>The optgroup disabled attribute</h1>
<form action="html/index.htm">
<label for="fruits">Choose a fruit:</label>
<select name="fruits" id="fruits">
<optgroup label="Citrus Fruits">
<option value="orange">Orange</option>
<option value="lemon">Lemon</option>
</optgroup>
<optgroup label="Tropical Fruits" disabled>
<option value="mango">Mango</option>
<option value="pineapple">Pineapple</option>
</optgroup>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
停用下拉選單中的 option
在這個程式碼中,我們將使用 disable 屬性停用下拉列表中的一個選項。
<!DOCTYPE html>
<html>
<body>
<h1>Option disabled attribute</h1>
<form action="html/index.htm">
<label for="fruits">Choose a car:</label>
<select>
<option value="volvo" disabled>Volvo</option>
<option value="Maruti">Maruti</option>
<option value="vw">VW</option>
<option value="car98">car98</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
停用 textarea 元素
在這個例子中,我們將使用 disable 屬性停用一個 textarea 標籤。
<!DOCTYPE html>
<html>
<body>
<h1>The textarea disabled attribute</h1>
<textarea disabled rows="7" cols="20">
At tutorialspoint you have access to multiple
courses to upskill your knowledge. We offer free tutorials
in all web development technologies.
</textarea>
</body>
</html>
啟用停用元素的指令碼
以下是一個例子,我們將使用 disabled 屬性和 input 標籤,並在點選按鈕時使用 javascript 啟用它。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Enable Text Input</title>
<script>
function enableInput() {
document.getElementById("textInput").disabled = false;
}
</script>
</head>
<body>
<h3>Click the button to enable text input</h3>
<label for="textInput">Enter Text:</label>
<input type="text" id="textInput" disabled>
<button onclick="enableInput()">Enable Input</button>
</body>
</html>
支援的瀏覽器
| 屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| disabled | 是 | 是 | 是 | 是 | 是 |
html_attributes_reference.htm
廣告




