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


HTML Input URL disabled用法及代碼示例


DOM輸入URL禁用屬性用於設置或返回是否必須禁用輸入URL字段。禁用的密碼字段為un-clickable,並且無法使用。它是一個布爾屬性,用於反映HTML Disabled屬性。默認情況下,在所有瀏覽器中通常以灰色顯示。

用法:

  • 它返回禁用的屬性。
    urlObject.disabled
  • 用於設置禁用的屬性。
    urlObject.disabled = true|false

屬性值:


  • true:它定義了輸入URL字段被禁用。
  • False:它具有默認值。它定義了輸入URL字段未禁用。

返回值:它返回一個布爾值,該布爾值表示是否禁用了輸入URL字段。

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

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        DOM Input URL disabled Property 
    </title> 
</head> 
  
<body> 
    <center> 
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1> 
  
        <h2> 
          DOM Input URL Disabled Property 
      </h2> 
  
        <label for="uname"
               style="color:green"> 
      </label> 
  
            <form id="geeks"> 
                <input type="url"
                       id="gfg"
                       placeholder="Enter URL" 
                       size="20"
                       pattern="https?://.+" 
                       title="Include http://" 
                       maxlength="20" 
                       disabled> 
            </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").disabled; 
                    
                    document.getElementById( 
                      "GFG").innerHTML = link; 
                } 
            </script> 
    </center> 
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

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

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        DOM Input URL disabled Property 
    </title> 
</head> 
  
<body> 
    <center> 
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1> 
  
        <h2> 
          DOM Input URL Disabled Property 
      </h2> 
  
        <label for="uname" 
               style="color:green"> 
      </label> 
  
            <form id="geeks"> 
                <input type="url"
                       id="gfg" 
                       placeholder="Enter URL"
                       size="20" 
                       pattern="https?://.+"
                       title="Include http://"
                       maxlength="20" 
                       disabled> 
            </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").disabled = "false"; 
                    
                    document.getElementById( 
                      "GFG").innerHTML = link; 
                } 
            </script> 
    </center> 
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:DOM輸入URL禁用屬性支持的瀏覽器如下:

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


相關用法


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