【问题标题】:HTML5 video ontimeupdate event doesn't work in Google ChromeHTML5 视频 ontimeupdate 事件在 Google Chrome 中不起作用
【发布时间】:2013-03-22 23:39:51
【问题描述】:

我正在尝试this example 中的 HTML5 视频标签,但并非一切正常。

我想使用ontimeupdate事件打印当前视频时间:

<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<video src="test.ogv" width='640' height='480' controls='controls'>
</video>
<div id=time>time</div>
<script>
var video = document.getElementsByTagName('video')[0];
var time = document.getElementById('time');
video.ontimeupdate = function(e) {
  time.innerHTML="Current time: " + video.currentTime;
}
</script>
</body>
</html>

这适用于 Opera 和 Firefox,但不适用于 Google Chrome。 那么,为什么这段代码在 Chrome 中不起作用?

【问题讨论】:

    标签: google-chrome html5-video


    【解决方案1】:

    这对我有用,也许 chrome 的错误/故障你的代码不起作用

    <html>
    <head>
    <meta charset="UTF-8">
    </head>
    <body>
    <video src="test.mp4" width='640' height='480' controls='controls' ontimeupdate="timeupdate();">
    </video>
    <div id=time>time</div>
    <script>
        var video = document.getElementsByTagName('video')[0];
        var time = document.getElementById('time');
        function timeupdate() {
            time.innerHTML = 'Current time: ' + video.currentTime;
        }
    </script>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 2019-03-20
      • 1970-01-01
      相关资源
      最近更新 更多