[英]I want one button to switch between two functions based on time?
What i have is a simple website where you input a number and when you click a button it divdes it by 16 and the answer pops up.我拥有的是一个简单的网站,您可以在其中输入一个数字,当您单击一个按钮时,它会将其除以 16,然后就会弹出答案。 But what i want to do is divide it by either 16 or 11 based on the time the button is clicked like if its earlier than 10:00 then it would divded it by 11 and anything later it would divide by 16.
但是我想要做的是根据单击按钮的时间将其除以 16 或 11,就像它早于 10:00 一样,然后将其除以 11,然后将其除以 16。
button.addEventListener('click', (e) => {
if (!hasSubmitted) {
hasSubmitted = true
result.classList.remove('hidden')
}
value.value = Number(input.value / 16)
})
how do i make both functions work on the same button.我如何让这两个功能在同一个按钮上工作。 I have no idea what to try since im totally new to javascript.
我不知道该尝试什么,因为我对 javascript 完全陌生。
Get the time, then set the amount to divide by depending on the hour.获取时间,然后根据小时设置除以的数量。
button.addEventListener('click', (e) => {
if (!hasSubmitted) {
hasSubmitted = true
result.classList.remove('hidden')
}
var hour = (new Date()).getHours();
var divisor = hour < 10 ? 11 : 16;
value.value = input.value / divisor;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.