在 HTML 中當媒體的回放位置發生變化時執行指令碼?
ontimeupdate 屬性事件,例如影片播放位置改變時觸發。它可以在影片或音訊中快進或快退。
示例
你可以嘗試執行以下程式碼來實現 ontimeupdate 屬性 −
<!DOCTYPE html> <html> <body> <h2 id="test">Play</h2> <video id = "myid" width="320" height = "176" controls ontimeupdate = "myFunction()"> <source src = "/html5/foo.ogg" type = "video/ogg" /> <source src = "/html5/foo.mp4" type = "video/mp4" /> Your browser does not support the video element. </video> <script> function myFunction() { document.getElementById("test").innerHTML = "Current position: " + document.getElementById("myid").currentTime; } </script> </body> </html>
廣告