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


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