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
相關用法
- HTML <track> label屬性用法及代碼示例
- HTML OptionGroup label用法及代碼示例
- HTML Label form用法及代碼示例
- HTML Option label用法及代碼示例
- HTML Label htmlFor用法及代碼示例
- HTML Track src用法及代碼示例
- HTML Track kind用法及代碼示例
- HTML Track readyState用法及代碼示例
- HTML Track srclang用法及代碼示例
- HTML Track default用法及代碼示例
- HTML <label>用法及代碼示例
- HTML DOM Label用法及代碼示例
- HTML label屬性用法及代碼示例
- HTML <label> form屬性用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM Track label property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。