設定每個已停用的元素的樣式,使用 CSS


若要設定每個已停用的 <input> 元素的樣式,請使用 CSS :disabled 選擇器。你可以嘗試執行以下程式碼來設定已停用元素的樣式 −

示例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:enabled {
            background: blue;
         }
         input:disabled {
            background: red;
         }
      </style>
   </head>
   <body>
      <form action = "">
         Subject <input type = "text" name = "subject"><br>
         Student: <input type = "text" name = "student"><br>
         Age: <input type = "number" name = "age" disabled><br>
      </form>
   </body>
</html>

更新於: 2020 年 6 月 30 日

485 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告