将时间存储在本地存储中

时间:2017-12-03 20:26:51

标签: javascript arrays dom local-storage array-push

我正在尝试将已失效的时间推送到本地存储。每当用户单击提交按钮时,时钟停止并计算持续时间。我想将持续时间推送到本地存储中的数组。在最后一次点击后,我想获取整个数组来计算总时间。 SO中有几个类似的问题,但没有一个完全符合这个目的。我可以在我的本地存储中看到一个带有键的数组:'Time'已创建,但它没有填充。 代码:

let answerButton = document.querySelector('#send')
answerButton.addEventListener('click', function () {
  TotalTime.stop()
  TotalTime.duration()
  clearTimeout(window.countdownTimer)
  timer()
  let totalTime = []
  TotalTime.duration().push(window.localStorage.setItem('Time', JSON.stringify(totalTime)))
})

0 个答案:

没有答案