简体   繁体   English

我想要一键根据时间在两个功能之间切换?

[英]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.

相关问题 每次单击按钮,我都想在两个功能之间切换 - On every button click, I want to switch between two functions 我想要一个按钮中有两个功能 - I want Two functions in one button 我想在两个功能之间切换,这段代码只工作一次,但我想让它每次点击都工作 - i want to toggle between two functions this code works only one time but i want to make it work each time i click 如何使一个按钮在两种功能之间切换? - How to make a button to switch between two functions? 我想在HTML中彼此重叠两个文本区域,然后单击按钮切换它们的堆叠顺序 - I want to have two textareas on top of one another in HTML, and switch the order they are stacked, with click of a button 如何将这两个按钮功能合并为一个,如开/关开关 - How do I merge these two button functions into one, like an on/off switch 我想将这两个功能合而为一 - I want to put these two functions in one function 使用一个按钮打开/关闭页面上的链接:toggle()两个功能 - Switch on / off Links on the page with one button: toggle() two functions 两个功能; 检查输入文件和文本区域,我也想禁用提交按钮,如何将功能合二为一? - Two functions; checking the input file and the text area and I also want to disable the submit button how do I make the functions into one? 如何在两个功能之间切换? - How to switch between two functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM