HTML DOM 輸入搜尋 size 屬性


HTML DOM 輸入搜尋 size 屬性用於設定或返回輸入搜尋欄位的 size 屬性值。它用於定義以字元為單位的搜尋欄位寬度。預設寬度為 20 個字元。

語法

- 的語法如下:

設定 Search size 屬性 -

searchObject.size = number

此處,number 表示以字元為單位的搜尋欄位寬度。預設寬度為 20 個字元。

示例

我們來看看一個 Input search size 屬性的示例 -

即時演示

<!DOCTYPE html>
<html>
<body>
<h1>Input search size property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits">
</form>
<p>Change the Search field width by clicking the below button</p>
<button onclick="changeSize()">CHANGE</button>
<p id="Sample">
<script>
   function changeSize() {
      document.getElementById("SEARCH1").size+=20;
      var s=document.getElementById("SEARCH1").size;
      document.getElementById("Sample").innerHTML="The search field width is now "+ s;
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 -

單擊 CHANGE 按鈕 -

更新於: 19-2 月-2021

81 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

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