HTML DOM Input 搜尋值屬性


HTML DOM Input search 值屬性與具有 type=”search”和 value 屬性的 input 元素相關聯。它用於返回輸入搜尋欄位 value 屬性的值或將其設定為該值。此屬性用於指定搜尋欄位的預設值,並且還可以將值更改為使用者輸入。

語法

以下是 − 語法

設定 value 屬性 −

searchObject.value = text;

此處,text 用於指定搜尋欄位的值。

示例

我們來看看一個 input search 值屬性的示例 −

實際演示

<!DOCTYPE html>
<html>
<body>
<h1>Input search Value property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits">
</form>
<p>Get the above element value by clicking the below button</p>
<button onclick="getValue()">Get Value</button>
<p id="Sample"></p>
<script>
   function getValue() {
      var t = document.getElementById("SEARCH1").value;
      document.getElementById("Sample").innerHTML = "The value for the input field is : "+t;
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

在鍵入一些文字然後單擊“獲取值”按鈕之後 −

更新日期: 2021-2-19

468 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

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