我无法q
使用javascript函数更新变量的值。我有一个计时器,当按下“播放”按钮时启动,然后连续触发当前需求功能
$(document).ready(function(){
$("#main_video").on(
"timeupdate",
function(event){
currentDemand(this.currentTime);
});
});
// Initiate Demand
var q = 0;
function currentDemand(currentTime){
console.log(currentTime);
if ( 0 <= currentTime < 10) {
q === 0;
}
else if ( 10 <= currentTime < 12.5 || 57.5 <= 60) {
q === 1;
}
else if ( 12.5 <= currentTime < 17.5 || 55 <= currentTime < 57.5) {
q === 2;
}
else if ( 17.5 <= currentTime < 20 || 50 <= currentTime < 55) {
q === 3;
}
else if (20 <= currentTime < 25 || 47.5 <= currentTime < 50) {
q === 4;
}
else if ( 25 <= currentTime < 27.5 || 45 <= currentTime < 47.5 ) {
q === 5;
}
else if ( 27.5 <= currentTime < 32.5 || 42500 <= currentTime < 45 ) {
q === 6;
}
else if ( 32.5 <= currentTime < 35 || 40 <= currentTime < 42.5 ) {
q === 7;
}
else if ( 45 <= currentTime < 47.5 ) {
q === 8;
}
console.log(q);
$("#currentDemand").text(q);
}
currentTime
正在正确记录应将其放在间隔中的值,但未q
设置。它可能与范围有关,我只是不知道如何解决它,以便q
正确更新并放入#currentDemand
div中。
如何设置q
更新?
这不是测试currentTime
两个值之间是否正确的方法:
else if ( 10 <= currentTime < 12.5 || 57.5 <= 60) {
它就像您写的一样被解析:
else if ( ((10 <= currentTime) < 12.5) || (57.5 <= 60)) {
由于57.5
始终小于60
,因此整个表达式将始终为true。但是10 <= currentTime < 12.5
也总是如此,因为10 <= currentTime
是true
或false
,并且在与另一个数字比较时将它们转换为1
或0
。并且1和0均小于12.5。
它应写为:
else if ( (10 <= currentTime && currentTime < 12.5) || (57.5 <= currentTime && currentTime < 60) ) {
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句