How to register a button after 10 seconds in javascript

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.