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


HTML Anchor hreflang用法及代碼示例


HTML DOM中的DOM Anchor hreflang屬性用於設置或返回URL或鏈接的hreflang屬性的值。 hreflang屬性用於指定鏈接文檔的語言。

用法:

  • 它返回hreflang屬性。
    anchorObject.hreflang
  • 它用於設置hreflang屬性。
    anchorObject.hreflang = languagecode

屬性值:


  • languagecode:它指定兩個字母代碼,代表鏈接文檔的語言。

返回值:它返回一個字符串值,該字符串值表示鏈接文檔的語言。

示例1:本示例返回hreflang屬性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        HTML DOM Anchor hreflang Property 
    </title> 
</head> 
  
<body> 
    <center> 
        <h1> 
          GeeksForGeeks 
      </h1> 
  
        <h2> 
          DOM Anchor hreflang Property 
      </h2> 
  
        <p>Welcome to 
            <a href= 
  "http://www.example.com:4097/test.htm#part2" 
               id="GFG" 
               rel="nofollow" 
               hreflang="en-us" 
               target="_self">  
                GeeksforGeeks  
            </a> 
        </p> 
  
        <button onclick="myGeeks()"> 
          Submit 
      </button> 
  
        <p id="sudo"
           style="color:green; 
                  font-size:25px;"> 
      </p> 
  
        <script> 
            function myGeeks() { 
                
                var x =  
                    document.getElementById( 
                      "GFG").hreflang; 
                
                document.getElementById( 
                  "sudo").innerHTML = x; 
            } 
        </script> " 
    </center> 
</body> 
  
</html>

輸出:

在單擊按鈕之前:

單擊按鈕後:

示例2:本示例設置hreflang屬性。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        HTML DOM Anchor hreflang Property 
    </title> 
</head> 
  
<body> 
    <center> 
        <h1> 
          GeeksForGeeks 
      </h1> 
  
        <h2> 
          DOM Anchor hreflang Property 
      </h2> 
  
        <p>Welcome to 
            <a href= 
  "http://www.example.com:4097/test.htm#part2" 
               id="GFG" 
               rel="nofollow" 
               hreflang="en-us" 
               target="_self">  
                GeeksforGeeks  
            </a> 
        </p> 
  
        <button onclick="myGeeks()"> 
          Submit 
      </button> 
  
        <p id="sudo" 
           style="color:green; 
                  font-size:25px;"> 
      </p> 
  
        <script> 
            function myGeeks() { 
                
                var x =  
                    document.getElementById( 
                      "GFG").hreflang = "fr"; 
                
                document.getElementById( 
                  "sudo").innerHTML =  
                  "The value of the hrefkang attribute"+ 
                  " was changed to " + x; 
            } 
        </script> " 
    </center> 
</body> 
  
</html>

輸出:

在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:下麵列出了DOM Anchor hreflang屬性支持的瀏覽器:

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


相關用法


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