javascript - 如何检查 jquery.each 循环中正在运行的计时器
问题描述
我正在使用easytimer(https://github.com/albert-gonzalez/easytimer.js)并且遇到了问题。我在一页上创建了多个计时器,每个计时器都有自己的开始和停止按钮。现在我想确保只有一个计时器同时运行。所以我想如果我点击计时器 3 的开始按钮,它应该检查所有其他计时器是否正在运行然后停止它们。
下面是我的代码
$('tr.step').each(function (index) {
var timer = new easytimer.Timer();
btnStart.off('click').on('click', (event) => {
event.preventDefault();
if (timer.isRunning()) {
console.log(timer + index + 'is running');
}
timer.start({
callback: function (timer) {
valTimer.html(
timer.getTimeValues().toString()
);
}
});
btnStart.hide();
btnStop.fadeIn(1000);
});
btnStop.off('click').on('click', (event) => {
event.preventDefault();
timer.stop();
});
因此,请任何人帮助我如何检查正在运行的计时器并在开始计数新计时器之前将其停止。
解决方案
推荐阅读
- r - 我正在尝试创建一个模型,该模型生成一个包含四个字符 {a、b、c、d} 的 256 个唯一组合的列表
- powershell - 相当于 Cat ./* ../path2/* > file.sql 的 Powershell
- dart - Dart FFI 类型映射
- java - 如何在unirest中发送文件
- python - 获取当前事务被中止,在尝试将数据插入 postgres 表时忽略命令直到事务块错误结束
- android - Sunable 可以在 Playstore 上上传签名的 apk
- compare - 通过命令行比较 2 个 RPT 报告
- typescript - 从类型参数中获取类型的补码
- devexpress - DxDataGrid 自定义寻呼机
- python - SQLAlchemy 在对象持久化到数据库之前评估关系