当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。