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


HTML Track label用法及代碼示例


DOM軌道標簽屬性用於設置或返回軌道的label屬性的值。它用於指定文本軌道的標簽。

用法:

  • 它用於返回label屬性。
    trackObject.label
  • 它還用於設置標簽屬性。
    trackObject.label = label

值:


  • label:它用於指定文本軌道的標題。

返回值:它以字符串形式返回軌道的標簽。

例:獲取標簽屬性的值。

<html> 
  
<head> 
    <style> 
        body { 
            text-align:center; 
        } 
          
        h1 { 
            color:green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1>GeeksforGeeks</h1> 
    <h2>Track label Property</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" 
               default> 
  
            <source id="myTrack" 
                    src= 
"https://contribute.geeksforgeeks.org/wp-content/uploads/11.mp4" 
                    type="video/mp4"> 
  
    </video> 
  
    <p>Click the button to get the 
      label property of the track.</p> 
  
    <button onclick="myFunction()"> 
        Get Label 
    </button> 
  
    <p id="gfg"></p> 
    <!-- Script to get the label value -->
    <script> 
        function myFunction() { 
            var x =  
               document.getElementById("myTrack1"); 
            
            document.getElementById( 
              "gfg").innerHTML = x.label; 
        } 
    </script> 
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

示例2:設置標簽屬性的值。

<html> 
  
<head> 
    <style> 
        body { 
            text-align:center; 
        } 
          
        h1 { 
            color:green; 
        } 
    </style> 
</head> 
  
<body> 
    <h1>GeeksforGeeks</h1> 
    <h2>Track label Property</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 set the 
      label property of the track.</p> 
  
    <button onclick="myFunction()"> 
        Set Label 
    </button> 
  
    <p id="gfg"></p> 
    <!-- Script to set the label value -->
    <script> 
        function myFunction() { 
            var x =  
                document.getElementById("myTrack1"); 
            
            x.label = "French"; 
            
            document.getElementById("gfg").innerHTML =  
              "The value of label is changed to " + myTrack1.label; 
        } 
    </script> 
</body> 
  
</html>

輸出:
在單擊按鈕之前:

單擊按鈕後:

支持的瀏覽器:

  • 穀歌瀏覽器
  • Internet Explorer 10.0+
  • Opera


相關用法


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