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>
廣告