var timer = setInterval(function () {
var secs = ytplayer.getCurrentTime();
var minutes = Math.floor(secs / 60);
var seconds = Math.floor(secs % 60);
var tsecs = ytplayer.getDuration();
var tminutes = Math.floor(tsecs / 60);
var tseconds = Math.floor(tsecs % 60);
var time = minutes + ":" + seconds + " / " + tminutes + ":" + tseconds;
document.getElementById('currenttime').innerHTML = time;
}, 1000);
此代码在 Firefox 中不起作用,但在 Chrome 和 IE 中起作用。
我检查了 firebug,它说变量 secs、分钟、秒、tsecs、t分钟、tseconds 和时间未定义。
我不知道如何解决这个问题,因为我确实使用 var 来定义它们。有谁知道我做错了什么?
谢谢
最佳答案
听起来您有一个 id 为 ytplayer
的元素,并假设 window.ytplayer
将自动创建。
不要做出这样的假设。使用 document.getElementById
(并确保您有一个触发标准模式的 Doctype)。
关于JavaScript 无法在 Firefox 中运行 : undefined variables?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10616242/