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


HTML textarea minlength用法及代碼示例


HTML DOM textarea minlength屬性用於設置或返回textarea字段的minlength屬性的值。它指定元素中允許的最小字符數。

用法:

  • 它返回minLength屬性。
    textareaObject.minLength
  • 它用於設置minLength屬性。
    textareaObject.minLength = number

屬性值:



  • number:它指定textarea元素中允許的最少字符數。

返回值:它返回一個數字值,該值表示Textarea字段中允許的最小字符數。

範例1:HTML程序說明如何返回maxlength屬性。

<!DOCTYPE html> 
<html> 
  
<body> 
    <center> 
        <h1 style="color:green;  
                font-style:italic;"> 
            GeeksforGeeks 
        </h1> 
  
        <h2 style="color:green;  
                font-style:italic;"> 
            DOM Textarea minlength Property 
        </h2> 
  
        <textarea rows="4" cols="50" 
                id="GFG" minlength="6"> 
            write here....  
        </textarea> 
        <br><br> 
  
        <button onclick="myGeeks()"> 
            Submit 
        </button> 
  
        <p id="sudo"></p> 
  
        <script> 
            function myGeeks() { 
  
                // Return max length allowed in the textarea field.  
                var x = document.getElementById("GFG").minLength; 
  
                document.getElementById("sudo").innerHTML = 
                    "There are only " + x + " minimum characters" + 
                    "are allowed in a Textarea Field.";; 
            }  
        </script> 
</body> 
  
</html>

輸出:

  • 在單擊按鈕之前:
  • 單擊按鈕後:

例子:HTML程序說明如何設置minlength屬性。

<!DOCTYPE html> 
<html> 
  
<body> 
    <center> 
        <h1 style="color:green;  
                font-style:italic;"> 
            GeeksforGeeks 
        </h1> 
  
        <h2 style="color:green;  
                font-style:italic;"> 
            DOM Textarea minlength Property 
        </h2> 
  
        <textarea rows="4" cols="50" id="GFG" minlength="6"> 
            write here....  
        </textarea> 
        <br> 
        <br> 
  
        <button onclick="myGeeks()"> 
            Submit 
        </button> 
  
        <p id="sudo"></p> 
  
        <script> 
            function myGeeks() { 
  
                // Return max length allowed in the textarea field.  
                var x = document.getElementById("GFG").minLength = "9"; 
  
                document.getElementById("sudo").innerHTML = 
                    "There are only " + x + " minimum characters" + 
                    "are allowed in a Textarea Field.";; 
            }  
        </script> 
</body> 
  
</html>

輸出:

  • 在單擊按鈕之前:
  • 單擊按鈕後:



相關用法


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