Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:UncaughtTypeError:未能设置';价值';在'上的属性;HTMLProgressElement';:提供的双精度值是非有限的_Jquery - Fatal编程技术网

jQuery:UncaughtTypeError:未能设置';价值';在'上的属性;HTMLProgressElement';:提供的双精度值是非有限的

jQuery:UncaughtTypeError:未能设置';价值';在'上的属性;HTMLProgressElement';:提供的双精度值是非有限的,jquery,Jquery,我知道也有类似的问题,但对我目前的问题来说,似乎没有什么太大的作用。我有一个带有进度条的简单音频播放器: $(document).ready(function() { $(".audio-clip .volume").on("input", function() { var audio = $(this) .closest("div") .find("audio")[0]; audio.volume = this.value; }); $("

我知道也有类似的问题,但对我目前的问题来说,似乎没有什么太大的作用。我有一个带有进度条的简单音频播放器:

$(document).ready(function() {
  $(".audio-clip .volume").on("input", function() {
    var audio = $(this)
      .closest("div")
      .find("audio")[0];
    audio.volume = this.value;
  });

  $(".audio-clip .position").on("input", function() {
    var audio = $(this)
      .closest("div")
      .find("audio")[0];
    audio.currentTime = (audio.duration / 100) * this.value;
  });

  $("audio").on("timeupdate", function() {
    var pc = (audio.currentTime / audio.duration) * 100;
    $(this)
      .closest("div")
      .find(".position")
      .val(pc);
  });
在html中

   <label>
    Position:
    <input type="range" class="position" min="0" max="100" step="1" value="0" />

    <progress class="nes-progress is-pattern position" value="0" max="100"></progress>
  </label>

请确保
pc
是一个有效的数字,然后再尝试使用它来设置值

  $("audio").on("timeupdate", function() {
    var pc = (audio.currentTime / audio.duration) * 100;
    if (isNaN(pc)) {
      return;
    }
    $(this)
      .closest("div")
      .find(".position")
      .val(pc);
  });

我打赌
audio.duration
0
,导致被0除法。
console.log(pc)
显示了什么?@Barmar实际上控制器工作正常,加载的音频文件有一个duration,所有都正常工作,但每次加载的文件都会出现以下错误:(回答我的问题,发生这种情况时,
pc
的值是多少?您忘记在上一个函数中设置
audio
)。
  $("audio").on("timeupdate", function() {
    var pc = (audio.currentTime / audio.duration) * 100;
    if (isNaN(pc)) {
      return;
    }
    $(this)
      .closest("div")
      .find(".position")
      .val(pc);
  });