HTML DOM 輸入 URL maxLength 屬性


HTML DOM Input URL maxLength 屬性返回/設定輸入 URL 的 maxLength 屬性。如果未定義,該屬性返回“ -1”。

語法

以下是語法 −

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

示例

讓我們看一個使用 Input URL maxLength 屬性的示例 −

 線上演示

<!DOCTYPE html>
<html>
<head>
<title>Input URL maxLength</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 id="Google">
<fieldset>
<legend>URL-maxLength</legend>
<label for="URLSelect">URL :
<input type="url" id="URLSelect" maxLength="10">
</label>
<input type="button" onclick="logIN()" value="Log In">
<input type="button" onclick="changeMaxLength()" value="Change Maxlength">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputURL = document.getElementById("URLSelect");
   divDisplay.textContent = 'Maxlength: '+inputURL.maxLength;
   function changeMaxLength() {
      inputURL.maxLength += 10;
      divDisplay.textContent = 'Maxlength: '+inputURL.maxLength;
   }
   function logIN(){
      if(inputURL.value !== '')
         divDisplay.textContent = 'Could not identify url, Redirecting to '+inputURL.form.id;
   }
</script>
</body>
</html>

輸出

將產生以下輸出 −

在單擊“更改最大長度”按鈕之前 −

在單擊“更改最大長度”按鈕之後 −

在單擊“登入”按鈕並設定電子郵件輸入 −

更新於: 30-7 月-2019

89 次瀏覽

開啟你的 職業之旅

完成課程獲得認證

開始
廣告
© . All rights reserved.