最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

JavaScript 中的倒計(jì)時(shí)器沒(méi)有停止

JavaScript 中的倒計(jì)時(shí)器沒(méi)有停止

慕蓋茨4494581 2023-12-04 16:35:13
我有一個(gè)計(jì)時(shí)器,從 5:00 分鐘開始倒計(jì)時(shí),但它不會(huì)停止!它只會(huì)變得消極。超文本標(biāo)記語(yǔ)言<p>Click the button to begin the quiz. Good Luck!</p>            <button id="start" class="button">Start</button>                <div class="timer">                Timer: <span id="time"> 5:00 </span> minutes            </div>JavaScriptdocument.getElementById('time').innerHTML = 05 + ":" + 00;function startTimer() {    var p_time = document.getElementById('time').innerHTML;    var timeArray = p_time.split(/[:]+/);    var min = timeArray[0];    var sec = checkSecond((timeArray[1]-1));    if(sec==59){min=min-1}    if(min <= 0 && sec == 0) {alert("Time is up!")}    document.getElementById('time').innerHTML = min + ":" + sec;    setTimeout(startTimer, 1000);}function checkSecond(seconds) {    if(seconds <10 && seconds >= 0) {seconds ="0" + seconds};    if(seconds <0) {seconds = "59"};    return seconds;}CSS.timer {    color: var(--primary);    font-size: 16px;    font-weight: bold;    margin: 10px;}我有 JS 說(shuō),當(dāng)分鐘小于或等于 0 并且秒等于 0 時(shí),則發(fā)出警報(bào)“時(shí)間到了”。因此,我收到彈出警報(bào),但是一旦我在彈出窗口上單擊“確定”,計(jì)時(shí)器就會(huì)不斷倒計(jì)時(shí)為負(fù)數(shù)。另外,在圖片中,“5:00”沒(méi)有顯示 - 它只顯示一個(gè)零。
查看完整描述

2 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

你必須告訴它停止。例如,如果時(shí)間到了就返回。就像是


if(min <= 0 && sec == 0) {return alert("Time is up!")}

//                        ^ now the next statements won't run

document.getElementById('time').innerHTML = min + ":" + sec;

setTimeout(startTimer, 1000);


查看完整回答
反對(duì) 回復(fù) 2023-12-04
?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

clearTimeout計(jì)時(shí)器完成 5 分鐘后,您需要?jiǎng)h除計(jì)時(shí)器。

如果 stackoverflow 片段不起作用,請(qǐng)檢查此 - https://jsfiddle.net/e5v80xmk/

document.getElementById('time').innerHTML = 05 + ":" + 00;

document.getElementById('start').addEventListener('click', startTimer);


var timerRef = null;


function startTimer() {

  var p_time = document.getElementById('time').innerHTML;

  var timeArray = p_time.split(/[:]+/);

  var min = timeArray[0];

  var sec = checkSecond((timeArray[1] - 1));

  if (sec == 59) {

    min = min - 1

  }


  document.getElementById('time').innerHTML = min + ":" + sec;


  if (min <= 0 && sec == 0) {

    clearTimeout(timerRef)

    alert("Time is up!")

    return

  }



  timerRef = setTimeout(startTimer, 1000);

}


function checkSecond(seconds) {

  if (seconds < 10 && seconds >= 0) {

    seconds = "0" + seconds

  };

  if (seconds < 0) {

    seconds = "59"

  };

  return seconds;

}

<p>Click the button to begin the quiz. Good Luck!</p>

<button id="start" class="button">Start</button>

<div class="timer">

  Timer: <span id="time"> 5:00 </span> minutes

</div>


查看完整回答
反對(duì) 回復(fù) 2023-12-04
  • 2 回答
  • 0 關(guān)注
  • 213 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)