當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML Input Email maxLength用法及代碼示例

HTML DOM中的Input Email maxLength屬性用於設置或返回電子郵件輸入字段的maxlength屬性值。它指定電子郵件字段中允許的最大字符數。輸入電子郵件的maxLength屬性的默認值為524288。

用法:

  • 它返回Input Email maxLength屬性。
    emailObject.maxLength
  • 它用於設置輸入電子郵件的maxLength屬性。
    emailObject.maxLength = number

屬性值:它包含單個值,用於指定“電子郵件最大長度”字段中允許的最大字符數。


返回值:它返回一個數字值,該值表示“電子郵件最大長度”字段中允許的最大字符數。

範例1:本示例說明如何返回Input Email maxLength屬性。

<!DOCTYPE html>  
<html>  
      
<head>  
    <title>  
        HTML DOM Input Email maxlength Property 
    </title>  
</head>      
  
<body style="text-align:center;"> 
  
    <h1> GeeksforGeeks</h1>  
  
    <h2>DOM Input Email maxLength Property</h2>  
      
    <form id="myGeeks"> 
        E-mail:<input type="email" id="email" maxlength="45"
            value="manaschhabra22@gmail.com">  
    </form><br> 
      
    <button onclick="myGeeks()">  
        Click Here!  
    </button>  
      
    <p id="GFG" style="font-size:25px;color:green;"></p>  
      
    <!-- Script to access input element with  
            type email attribute -->
    <script>  
        function myGeeks() {  
            var em = document.getElementById("email").maxLength; 
            document.getElementById("GFG").innerHTML = em;  
        }  
    </script>  
</body>  
  
</html>                    

輸出:
在單擊按鈕之前::

單擊按鈕後:

範例2:本示例說明如何設置“輸入電子郵件”的maxLength屬性。

<!DOCTYPE html>  
<html>  
      
<head>  
    <title>  
        HTML DOM Input Email maxlength Property 
    </title>  
</head>      
  
<body style="text-align:center;"> 
  
    <h1> GeeksforGeeks</h1>  
  
    <h2>DOM Input Email maxLength Property</h2>  
      
    <form id="myGeeks"> 
        E-mail:<input type="email" id="email" maxlength="45"
            value="manaschhabra22@gmail.com">  
    </form><br> 
      
    <button onclick="myGeeks()">  
        Click Here!  
    </button>  
      
    <p id="GFG" style="font-size:20px;color:green;"></p>  
      
    <!-- Script to set Input Email maxlength Property -->
    <script>  
        function myGeeks() {  
            var em = document.getElementById("email").maxLength 
                    = "70";                          
            document.getElementById("GFG").innerHTML 
                    = "The value of the maxlength attribute" 
                      + " was changed to:" + em;  
        }  
    </script>  
</body>  
  
</html>                                 

輸出:
在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:以下列出了DOM輸入Email maxLength屬性支持的瀏覽器:

  • 穀歌瀏覽器
  • IE瀏覽器
  • Firefox
  • Opera
  • Safari


相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM Input Email maxLength Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。