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

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

如何在Java Script中停止實時時間

如何在Java Script中停止實時時間

桃花長相依 2022-05-14 14:36:29
我想在 java 腳本中停止直播時間。我該怎么做。這是我的實時java腳本源代碼。        setInterval(function(){        var d = new Date()        var h = d.getHours()        var m = d.getMinutes()        var s = d.getSeconds()        h = (h < 10) ? ("0" + h) : h;        m = (m < 10) ? ("0" + m) : m;        s = (s < 10) ? ("0" + s) : s;        document.getElementById("time").value = h +":"+m+":"+s}, 1000)document.getElementById("time").setAttribute("disabled","disabled")document.getElementById("time").clearInterval(value)
查看完整描述

1 回答

?
慕勒3428872

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

使用clearInterval函數https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval


WindowOrWorkerGlobalScope mixin 的 clearInterval() 方法取消了之前通過調用 setInterval() 建立的定時重復操作。


var interval = setInterval(function(){

        var d = new Date()

        var h = d.getHours()

        var m = d.getMinutes()

        var s = d.getSeconds()

        h = (h < 10) ? ("0" + h) : h;

        m = (m < 10) ? ("0" + m) : m;

        s = (s < 10) ? ("0" + s) : s;

        document.getElementById("time").value = h +":"+m+":"+s

}, 1000)


// this will cancel the interval when you want it to

clearInterval(interval);


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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