该函数不在事件侦听器中运行

我试图在单击按钮后显示一个Timer,当我在此eventlistner之外使用它时,但是当我调用此Watch.start()时,我的Timer类工作正常。在事件内部它什么都不做!我不知道我在这里想念的是什么,我是新手!

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

var Watch = new Stopwatch(timer);


let getMedia = navigator.mediaDevices.getUserMedia({
  video: true,
  audio: false
})


getMedia.then(async function (stream) {
  document.querySelector("#video").srcObject = stream;
});


getMedia.then(async function (stream) {
  let recorder = RecordRTC(stream, {
    type: "gif",
    width: 1280,
    height: 720,
    frameRate: 200,
    quality: 10,
  });

  window.addEventListener("click", function (event) {
    if (event.target.id == "startrecord") {
      buttonsContainer.innerHTML = `
          <div class="camera-done">
          <img id="camera-icon" src="./assets/recording.svg" alt="camera" />
              </div>
          <button id="doneButton">Listo</button>
          <div class="timer">00 : 00 . 00</div>
            `;
      recorder.startRecording();
         Watch.start();
    }
  })
评论
cnon
cnon

我认为您存在语法错误,}中的}附近

getMedia.then(async function (stream) {

查看Chrome控制台中的错误

点赞
评论