HTML DOM 輸入按鈕 disabled 屬性


HTML DOM 輸入按鈕 disabled 屬性可返回和修改 HTML 中輸入按鈕的 disabled 屬性。

語法

語法如下 −

1. 返回名稱

object.disabled

2. 修改名稱

object.disabled = true|false

示例

讓我們來看一個 disabled 屬性的示例 −

 動態演示

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM disabled Property</title>
<style>
   body{
      text-align:center;
   }
   .btn{
      display:block;
      margin:1rem auto;
      background-color:#db133a;
      color:#fff;
      border:1px solid #db133a;
      padding:0.5rem;
      border-radius:50px;
      width:80%;
   }
   .show-message{
      font-weight:bold;
      font-size:1.4rem;
      color:#ffc107;
   }
</style>
</head>
<body>
<h1>disabled Property Example</h1>
<input type="button" onclick="disableMe()" class="btn" value="Click me to Disable me">
<div class="show-message"></div>
<script>
   function disableMe() {
      var btn= document.querySelector(".btn");
      btn.disabled = true;
      document.querySelector(".show-message").innerHTML="Previously I'm enabled but now I'm disabled";
   }
</script>
</body>
</html>

輸出

將生成以下輸出 −

現在,單擊“Click me to Disable me”按鈕以停用紅色按鈕。

更新於:2019 年 7 月 30 日

101 次檢視

開啟 職業生涯

完成課程認證

立即開始
廣告
© . All rights reserved.