更新带有Javascript函数错误的变量

维吉突击

我无法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正确更新并放入#currentDemanddiv中。

如何设置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 <= currentTimetruefalse,并且在与另一个数字比较时将它们转换为10并且1和0均小于12.5。

它应写为:

else if ( (10 <= currentTime && currentTime < 12.5) || (57.5 <= currentTime && currentTime < 60) ) {

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

php - 带有 case + if 的函数错误

来自分类Dev

Javascript匿名函数错误

来自分类Dev

JavaScript子函数错误

来自分类Dev

mapreduce javascript函数错误

来自分类Dev

JSON返回并带有参数错误

来自分类Dev

.NET Web Api 2.1中带有Ninject绑定的无参数构造函数错误

来自分类Dev

传递带有react-google-charts的数组时,n.getFullYear不是函数错误

来自分类Dev

Firebase用户的context.auth仍存在allAuthenticatedUsers保护的Google函数错误,并带有UNAUTHENTICATED

来自分类Dev

to_json()函数错误地导出了带有float64的熊猫数据框

来自分类Dev

e.slice不是带有Kendo UI的ASP.NET MVC中的函数错误

来自分类Dev

带有输入和输出参数错误的函数 PLS-00103

来自分类Dev

JavaScript CANVAS绘图LineTo函数错误

来自分类Dev

javascript - 单击不是函数错误

来自分类Dev

没有出现函数错误

来自分类Dev

AngularJs中没有函数错误

来自分类Dev

没有出现函数错误

来自分类Dev

具有函数错误的枚举

来自分类Dev

Acess VBA-更新变量列(参数错误太少)

来自分类Dev

Firebase 云函数错误_:变量未定义

来自分类Dev

函数错误中的Javascript方法“不是函数”

来自分类Dev

没有匹配的函数错误C ++构造函数

来自分类Dev

JavaScript地理位置错误-回调函数错误

来自分类Dev

dplyr函数错误

来自分类Dev

Postgres函数错误

来自分类Dev

grep函数错误

来自分类Dev

内联函数错误

来自分类Dev

Excel函数错误

来自分类Dev

Excel函数错误

来自分类Dev

布尔函数错误