HTML DOM Textarea 屬性


HTML DOM Textarea disabled 屬性返回和修改 HTML 文件中的文字區域元素是否已停用。

語法

語法如下:-

1. 返回停用

object.disabled

2. 新增停用

object.disabled = true | false

讓我們看一個 HTML DOM Textarea disabled 屬性的示例

示例

即時演示

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      background: lightseagreen;
      height: 100vh;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
   }
</style>
<body>
<h1>DOM Textarea disabled Property Demo</h1>
<textarea placeholder="Hi! I'm placeholder text of a textarea element" rows="8" cols='20'></textarea>
<button onclick="set()" class="btn">Disable Textarea</button>
<script>
   function set() {
      document.querySelector("textarea").disabled = true;
   }
</script>
</body>
</html>

輸出

點選“停用文字區域”按鈕以停用文字區域元素。

更新於: 16-Feb-2021

107 次瀏覽

開啟您的職業生涯

透過完成本課程獲得認證

現在就開始
廣告