How to register a button after 10 seconds in javascript
This example describes how to register a button that can be clicked in 10 seconds after javascript is implemented. Share it with you for your reference. The specific analysis is as follows:
1. The initial status of the Registration button is unavailable, disabled
2. Start the timer, setInterval, and run the CountDown method once every second to set a global variable with an initial value of 10,
In the CountDown method, calculate the global variable reciprocal and write the reciprocal value to the Registration button (read the Protocol carefully (8 seconds left )).
3. Make the Registration button available until the value of the global variable is <= 0. Set the text of the button to "Agree! "
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Title> </title> <Script type = "text/javascript"> Var MyCount = 10; Var intervalID; Function CountDown (){ Var btnReg = document. getElementById ("btnReg "); If (btnReg ){ // Determine whether btnReg is null, // The network speed may be slow. After setInterval, The btnReg button has not been loaded. If (MyCount <= 0 ){ BtnReg. disabled = ""; // or btnReg. disabled = "disabled" BtnReg. value = "agree "; ClearInterval (intervalID); // clear the timer } Else { BtnReg. value = "please read the Protocol carefully (" + MyCount + "seconds left )"; MyCount --; } } } IntervalID = setInterval ("CountDown ()", 1000 ); </Script> </Head> <Body> <Textarea> Please agree to the agreement on this site </textarea> <br/> <Input id = "btnReg" type = "button" value = "agree" disabled = "disabled"/> </Body> </Html> |
I hope this article will help you design javascript programs.