HTML DOM Input URL size 屬性


Input URL size 屬性獲取/設定 input URL 的 size 屬性。如果未定義此屬性,它會返回“20”。

語法

以下是語法 −

  • 返回size 屬性
inputURLObject.size
  • 為 size 屬性設定一個數字
inputURLObject.size = number

示例

我們來看一個Input URL size 屬性的示例 −

 實際示例

<!DOCTYPE html>
<html>
<head>
<title>Input URL size</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>URL-size</legend>
<label for="URLSelect">URL:
<input type="url" id="URLSelect" size="10">
</label><br>
<input type="button" onclick="increaseVisibility()" value="Increase Visibility">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputURL = document.getElementById("URLSelect");
   function increaseVisibility() {
      inputURL.size = 30;
      divDisplay.textContent = 'Visibility Increased to '+inputURL.size;
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

點選“增加可見性”按鈕之前 −

點選“增加可見性”按鈕之後 −

更新時間: 30-7-2019

74 次瀏覽

啟動您的 職業生涯

完成該課程獲取認證

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