亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 HTML 中停止“設置間隔”

如何從 HTML 中停止“設置間隔”

RISEBY 2022-09-23 16:19:44
此代碼顯示了一個正在增長的間隔計時器。我正在使用setInterval,但我不知道如何停止ist。有一個叫做恩德()的放克。我可以用這個放克停止間隔計時器嗎?停止它的原因是,當我再次按下按鈕(在底部)時,第二個計時器就會啟動。我不知道怎么說,測試一下。```<!DOCTYPE html><html>  <head>    <title>Interval Timer</title>      <style>      @font-face {        font-family: sevenSegment;        src: url(SevenSegment.ttf);      }          h1{        font-family: sevenSegment;        font-size: 7em;        color: #969696;        line-height: 0%;      }      h2{        font-family: sevenSegment;        font-size: 5em;        color: #969696;        line-height: 0%;      }      .container{        position: absolute;        top: 50%;        left: 50%;        transform: translate(-50%, -50% );      }            .button1{        font-family: sevenSegment;        font-size: 1em;        color: #969696;                  border: none;      }    </style>  </head>  <body>    <div class="container">      <table>        <tr>          <td><h2 id="des">WORK</h2></td>                 </tr>        <tr>          <td><h1 id="count">00:00:45</h1></th>        </tr>        <tr>          <td><h2 id="des">REST</h2></td>         </tr>        <tr>          <td><h1 id="count2">00:00:15</h1></td>        </tr>         <tr>           <td><h2 id="des">Pause</h2></td>         </tr>         <tr>           <td><h1 id="count3">00:00:25</h1></td>         </tr>      </table>      <button class="button1" type="button" id="work">Work</button>      <button class="button1" type="button" id="rest">Rest</button>      <button class="button1" type="button" id="pause">Pause</button>    </div>   
查看完整描述

1 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

將間隔存儲在變量中,然后使用該變量停止間隔。但是,由于您在函數內啟動區間并在另一個函數內停止它,因此需要使用全局變量。首先聲明一個全局變量 x:

var x;

然后,替換:

setInterval(...

由:

x = setInterval(...

要停止間隔,只需致電

clearInterval(x);


查看完整回答
反對 回復 2022-09-23
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號