HTML DOM Input Search readOnly 屬性


HTML DOM Input Search readOnly 屬性用於設定或返回輸入搜尋欄位是否只讀。readOnly 屬性使元素不可編輯,但仍可以透過 tab 鍵或單擊對其進行焦點化。如果只讀元素中有預設值,則會在提交時將其傳送至伺服器。

語法

以下是語法 −

設定 readOnly 屬性 −

searchObject.readOnly = true|false

這裡,true 表示搜尋欄位只讀,而 false 則表示可讀寫。readOnly 屬性預設設定為 false。

示例

讓我們看一個 Search readOnly 屬性示例 −

<!DOCTYPE html>
<html>
<body>
<h1>Search readOnly property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits">
</form>
<p>Change the readOnly property of the above field by clicking the below button</p>
<button onclick="changeRead()">CHANGE</button>
<script>
   function changeRead() {
      document.getElementById("PASS1").readOnly = true;
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

點選 CHANGE 按鈕 −

更新於: 19-Aug-2019

瀏覽 79 次

開啟你的 事業

透過完成課程認證

開始學習
廣告
© . All rights reserved.