Home > front end >  How to use js to judge a certain time period button available?
How to use js to judge a certain time period button available?

Time:09-18

Var obj=new Date ();
Var hour=obj. GetHours ();
Var minute=obj. GetMinutes ();
Var second=obj. GetSeconds ();
Var dqtime=hour + + ":" + ":" + minute second;

If ((new Date (dqtime)) & lt; (new Date (11:00:00))) {
Document. The getElementById (" button "). The disabled=false;
} else {
Document. The getElementById (" button "). The disabled=true;
}

My purpose is just first button available before 11 o 'clock every day, but this line of code, a great god, please grant instruction,

CodePudding user response:

Can get two cases: click on the button to trigger, gets the current time, if the time more than 11 points to change state (enter the page also get a, look have exceed the time limit) 2: write the timer, every once in a while whether the time more than 11 points, more than change state cost (performance), it is recommended to use the first method, the second's a waste of resources
  • Related