简体   繁体   English

无法读取未定义的属性“toFixed”。 未捕获的类型错误

[英]Cannot read property 'toFixed' of undefined. Uncaught TypeError

I'm trying to understand why my code block doesn't work.我试图理解为什么我的代码块不起作用。 I am using JQuery as well as vanilla JS.我正在使用 JQuery 以及 vanilla JS。

Here's my code.这是我的代码。

 // update every 1 second on time.
  setInterval(function() {
    // get current time and duration of entire video
    let getTimePaused = video.currentTime;
    let vidTime = getTimePaused.toFixed(0);
    let formatTime = minTommss(vidTime);
    $(".timeLeft").text(
      minTommss(vidTime / 60) + " - " + minTommss((video.duration / 60) + 0.01)
    );
  }, 1000);

Any help is much appreciated.任何帮助深表感谢。

Thanks!谢谢!

I actually fixed it.我实际上修复了它。

In my case, the problem didn't have anything to do with toFixed() .就我而言,问题与toFixed()无关。

My problem was due to mixing JQuery and Vanilla Javascript.我的问题是由于混合了 JQuery 和 Vanilla Javascript。

Like this,像这样,

let video = $(".video");

video.on("timeupdate", function() {
    let colorPos = video.currentTime / video.duration;
    color.style.width = colorPos * 100 + "%";
    if (video.ended) {
      btn.className = "replay";
    }
  });

Solution解决方案

let video = document.querySelector(".video");

video.addEventListener("timeupdate", function() {
    let colorPos = video.currentTime / video.duration;
    color.style.width = colorPos * 100 + "%";
    if (video.ended) {
      btn.className = "replay";
    }
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取未定义的属性“toFixed” - Uncaught TypeError: Cannot read property 'toFixed' of undefined “ typeError:无法读取未定义的属性“用户名”。” - “typeError: Cannot read property 'username' of undefined.” 未捕获(承诺中)类型错误:无法读取未定义的属性“0”。 从 csv 文件中提取以填充数组 - Uncaught (in promise) TypeError: Cannot read property '0' of undefined. Pulling from a csv file to populate an array 未捕获的类型错误:无法读取未定义的属性“on”。 我也尝试重新安装电子 - Uncaught TypeError: Cannot read property 'on' of undefined. I have tried to reinstall electron as well Uncaught TypeError:无法读取未定义的属性“ push”。 应该做什么? - Uncaught TypeError: Cannot read property 'push' of undefined. What should be done? 如何捕获未捕获的类型错误:无法读取未定义的属性'datatable'。 错误 - How to catch Uncaught typeerror: cannot read property 'datatable' of undefined. error 无法读取未定义的属性“toFixed” - cannot read property "toFixed" of undefined 无法读取未定义的属性“toFixed” - Cannot read property 'toFixed' of undefined TypeError:无法读取未定义的属性“ get”。 是npm的问题吗? - TypeError: Cannot read property 'get' of undefined. Is npm the issue? TypeError:无法读取未定义的属性“ 0”。 React Redux应用 - TypeError: Cannot read property '0' of undefined. React Redux App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM