更改音頻/視頻持續時間時,將發生HTML DOM ondurationchange事件。音頻/視頻的持續時間從“NaN”更改為加載時的音頻/視頻的實際持續時間。
音頻/視頻的加載過程中發生以下事件:
- onloadstart
- ondurationchange
- onloadedmetadata
- onloadeddata
- onprogress
- oncanplay
- oncanplaythrough
用法:
- 在HTML中:
<element ondurationchange="myScript">
- 在JavaScript中:
object.ondurationchange = function(){myScript};
- 在JavaScript中,使用addEventListener()方法:
object.addEventListener("durationchange", myScript);
範例1:使用HTML
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM ondurationchange Event
</title>
</head>
<body>
<center>
<h1 style="color:green">GeeksforGeeks</h1>
<h2>HTML DOM ondurationchange Event</h2>
<video controls ondurationchange="GFGfun()">
<source src="Canvas.move_.mp4"
type="video/mp4">
</video>
<script>
function GFGfun() {
alert("The video duration has changed");
}
</script>
</center>
</body>
</html>
輸出:
範例2:使用JavaScript
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM ondurationchange Event</title>
</head>
<body>
<center>
<h1 style="color:green">GeeksforGeeks</h1>
<h2>HTML DOM ondurationchange Event</h2>
<video controls ondurationchange="GFGfun()">
<source src="Canvas.move_.mp4" type="video/mp4">
</video>
<script>
document.getElementById("durVideo").ondurationchange = function() {
GFGfun()
};
function GFGfun() {
alert("The video duration has changed");
}
</script>
</center>
</body>
</html>
輸出:
範例3:使用addEventListener()方法:
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM ondurationchange Event
</title>
</head>
<body>
<center>
<h1 style="color:green">GeeksforGeeks</h1>
<h2>HTML DOM ondurationchange Event</h2>
<video controls ondurationchange="GFGfun()">
<source src="mov_bbb.mp4" type="video/mp4">
</video>
<script>
document.getElementById(
"durVideo").addEventListener("durationchange", GFGfun);
function GFGfun() {
alert("The video duration has changed");
}
</script>
</center>
</body>
</html>
輸出:
支持的瀏覽器:下麵列出了HTML DOM ondurationchange Event支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- Firefox
- 蘋果Safari
- Opera
相關用法
- HTML onfocusin事件用法及代碼示例
- HTML onbeforeunload事件用法及代碼示例
- HTML onbeforeprint事件用法及代碼示例
- HTML oncanplay事件用法及代碼示例
- HTML onblur事件用法及代碼示例
- HTML fullscreenchange事件用法及代碼示例
- HTML onerror事件用法及代碼示例
- HTML onfocusout事件用法及代碼示例
- HTML onseeking事件用法及代碼示例
- HTML onclick事件用法及代碼示例
- HTML oncopy事件用法及代碼示例
- HTML onresize事件用法及代碼示例
- HTML onreset事件用法及代碼示例
- HTML onscroll事件用法及代碼示例
- HTML oncontextmenu事件用法及代碼示例
注:本文由純淨天空篩選整理自Vijay Sirra大神的英文原創作品 HTML | DOM ondurationchange Event。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。