如何看显示分钟和秒CurrentTime< video>在html5中如果使用jquery? [英] How see on display minute and second CurrentTime <video> in html5 if use jquery?

查看:242
本文介绍了如何看显示分钟和秒CurrentTime< video>在html5中如果使用jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在显示的CurrentTime分钟和第二个视频上看到。

I want see on display CurrentTime minute and second video.

var id = $('#main_video_player');

alert(id.get(0).currentTime); //worked i see '12.324543356'

var minnow=id.get(0).currentTime.split('.')[0];   
alert(minnow); //not worked

var secnow=id.get(0).currentTime.split('.')[1].substr('0','1');   
alert(secnow); //not worked

感谢大家的帮助=)

显示秒数的正确代码:

alert(time.toString().split('.')[0]);

以小时,分钟为单位显示正确时间的代码:

var id = $('#video');

timenow=id.get(0).currentTime;

if (parseInt(timenow)/60>=1) {
        var h = Math.floor(timenow / 3600);
        timenow = timenow - h * 3600;               
        var m = Math.floor(timenow / 60);
        var s = Math.floor(timenow % 60);
        if(h.toString().length<2){h='0'+h;}
        if(m.toString().length<2){m='0'+m;}
        if(s.toString().length<2){s='0'+s;}
        alert(h+' : '+m+' : '+s);          
    } else {
        var m = Math.floor(timenow / 60);
        var s = Math.floor(timenow % 60);
        if(m.toString().length<2){m='0'+m;}
        if(s.toString().length<2){s='0'+s;}
        alert(m+' : '+s);
}


推荐答案

你需要转换 currentTime String 执行 .split() .substr()就可以了,例如

You need to convert the currentTime to a String to perform .split() and .substr() on it, e.g.

var time = id.get(0).currentTime;
var minutes = time.toString().split('.')[0];   
var seconds = time.toString().split('.')[1].substr('0','1'); 

将它们转换回 float (与数字函数一起使用的数字是这样的:

To convert them back to a float (Number) for use with numerical functions do like so:

minutes = parseFloat(minutes);

参见 http://jsfiddle.net/NpgD5/23/ 的工作示例(点击视频获取时间)。

See http://jsfiddle.net/NpgD5/23/ for a working example (click on the video to get the time).

编辑: currentTime 以秒为单位返回时间,因此您的 minnow 变量实际上是秒, secnow 是毫秒,从 currentTime 获得分钟和秒的更好方法是:

currentTime returns the time in seconds so your minnow variable is actually seconds and secnow are milliseconds, a better way of getting minutes and seconds from currentTime is:

var time = id.get(0).currentTime;
var minutes = Math.floor(time / 60);   
var seconds = Math.floor(time); 

这篇关于如何看显示分钟和秒CurrentTime&lt; video&gt;在html5中如果使用jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆