重载后立即触发事件.不在"onclick"之后 [英] Event triggers immediately after reload. Not after "onclick"
问题描述
在我的第一个Pomodoro-App(计时器)因oncLick
失事的路上,应该启动计数器…
即使没有按钮单击触发蜂鸣也可以启动.我该如何预防?
On the way to my first Pomodoro-App (timer) shipwrecking with oncLick
, which should start the counter…
It starts even without beeing triggered by button click. How can I prevent that?
let display = document.getElementById("counter");
document.getElementById("ticker").onclick = function() {
timeChange(25);
};
// document.getElementById("ticker").addEventListener("click", function() {
// timeChange(25);
// });
function timeChange(seconds) {
// let seconds = 25;
seconds -= 1;
display.innerText = seconds;
page.firstChild.nodeValue = seconds;
if (seconds > 0) {
setTimeout(timeChange, 1000, seconds);
}
}
timeChange(25);
<body>
<div id="page">
<div id="counter"></div>
<button id="ticker">Start Pomodoro</button>
</div>
</body>
我已经找到同一问题的答案:
I already found an answer to the same(?) issue:
那是因为您要分配执行结果 rollDice(results)到您的clickButton.onclick函数
That's because you're assigning the result of executing rollDice(results) to your clickButton.onclick function
但是我没有(?)将函数的结果分配给onclick
But I did not(?) assign the result of my function to onclick
是因为我将onclick
分配给的参数(25)输入了吗?
Is it because of the argument (25) I put into the function to which the onclick
is assigned to?
非常感谢
推荐答案
删除:
timeChange(25);
从代码底部开始
Remove:
timeChange(25);
from the bottom of your code
这篇关于重载后立即触发事件.不在"onclick"之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!