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


HTML Input URL autocomplete用法及代碼示例


HTML DOM中的DOM輸入URL自動完成屬性用於設置或返回輸入URL字段的自動完成屬性的值。自動完成屬性用於指定自動完成屬性具有“on”值還是“off”值。當autocomplete屬性設置為on時,瀏覽器將根據用戶之前輸入的內容自動完成值。

用法:

  • 它返回輸入URL自動完成屬性。
    urlObject.autocomplete
  • 它用於設置輸入URL自動完成屬性。
    urlObject.autocomplete = "on|off"

屬性值:它包含下麵列出的兩個值:


  • on:它是默認值。它會自動完成值。
  • off:它定義了用戶應填寫URL輸入字段的值。它不會自動完成值。

返回值:它返回一個表示自動完成狀態的字符串值。

示例1:本示例說明了如何返回屬性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        DOM Input URL autocomplete Property 
    </title> 
</head> 
  
<body> 
    <center> 
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1> 
  
        <h2> 
          DOM Input URL autocomplete Property 
      </h2> 
  
        <label for="uname" 
               style="color:green"> 
      </label> 
  
            <form id="geeks"> 
                <input type="url"
                       id="gfg" 
                       placeholder="Enter URL" 
                       size="20"
                       value="GeeksForGeeks" 
                       pattern="https?://.+" 
                       title="Include http://" 
                       autocomplete="on"> 
            </form> 
            <br> 
            <br> 
  
            <button type="button" 
                    onclick="geeks()"> 
                Click 
            </button> 
  
            <p id="GFG" 
               style="color:green; 
                      font-size:25px;"> 
          </p> 
  
            <script> 
                function geeks() { 
                    
                    var link =     
                     document.getElementById( 
                       "gfg").autocomplete; 
                    
                    document.getElementById( 
                      "GFG").innerHTML = link; 
                } 
            </script> 
    </center> 
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

示例2:本示例說明了如何設置屬性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        DOM Input URL autocomplete Property 
    </title> 
</head> 
  
<body> 
    <center> 
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1> 
  
        <h2> 
          DOM Input URL autocomplete Property 
      </h2> 
  
        <label for="uname" 
               style="color:green"> 
      </label> 
  
            <form id="geeks"> 
                <input type="url"
                       id="gfg" 
                       placeholder="Enter URL" 
                       size="20" 
                       value="GeeksForGeeks" 
                       pattern="https?://.+" 
                       title="Include http://" 
                       autocomplete="on"> 
            </form> 
            <br> 
            <br> 
  
            <button type="button" 
                    onclick="geeks()"> 
                Click 
            </button> 
  
            <p id="GFG" 
               style="color:green; 
                      font-size:25px;"> 
          </p> 
  
            <script> 
                function geeks() { 
                    
                    var link =  
                        document.getElementById( 
                          "gfg").autocomplete = "off"; 
                    
                    document.getElementById( 
                      "GFG").innerHTML =  
                      "The value of the autocomplete attribute "+ 
                      "was changed to " + link; 
                } 
            </script> 
    </center> 
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:DOM輸入URL自動完成屬性支持的瀏覽器如下:

  • 穀歌瀏覽器
  • Internet Explorer 10.0以上
  • Firefox
  • Opera
  • Safari


相關用法


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