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


HTML srclang屬性用法及代碼示例


srclang屬性用於指定軌道文本的語言。 srclang屬性可以應用於<track>元素:

注意:srclang屬性是必需的,種類= “subtitles”。

例:下麵是srclang屬性的示例。

<html> 
  
<head> 
</head> 
  
<body style="text-align:center"> 
    <h1 style="color:green"> 
      GeeksforGeeks 
  </h1> 
    <h2>HTML srclang Attribute</h2> 
  
    <video width="100"
           height="100" 
           controls> 
  
        <track src= 
"https://contribute.geeksforgeeks.org/wp-content/uploads/11.mp4"
               id="myTrack1" 
               kind="subtitles"
               srclang="en" 
               label="English"> 
  
            <source id="myTrack"
                    src= 
"https://contribute.geeksforgeeks.org/wp-content/uploads/11.mp4" 
                    type="video/mp4"> 
    </video> 
  
    <p> 
      Click the button to get  
      the language of the track. 
  </p> 
  
    <button onclick="myFunction()"> 
        Get srclang 
    </button> 
  
    <p id="gfg"></p> 
    <!-- Script to get the  
      value of srclang property -->
    <script> 
        function myFunction() { 
            var x = 
                document.getElementById("myTrack1"); 
            
            document.getElementById( 
                "gfg").innerHTML = x.srclang; 
        } 
    </script> 
</body> 
  
</html>

輸出:單擊按鈕以獲取srclang屬性的值:

支持的瀏覽器:

  • 穀歌瀏覽器18.0
  • Internet Explorer 10.0
  • Firefox 31.0
  • Opera 15.0
  • Safari 6.0




相關用法


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