Check whether instances are available after the js control button is clicked.

Source: Internet
Author: User
Tags use definition

This article will show you whether the js control button is available after you click it. I hope this tutorial will be helpful to you.

Usage:

Object. disabled = false | true;

1. Obtain the verification code within the specified time to prevent multiple requests:

The Code is as follows: Copy code

<Input type = "button" id = "btn" value = "get verification code for free"/>
<Script type = "text/javascript">
Var wait = 60;
Function time (o ){
If (wait = 0 ){
O. removeAttribute ("disabled ");
O. value = "get verification code for free ";
Wait = 60;
} Else {
O. setAttribute ("disabled", true );
O. value = "resend (" + wait + ")";
Wait --;
SetTimeout (function (){
Time (o)
},
1000)
}
}
Document. getElementById ("btn"). onclick = function () {time (this );}

</Script>

2. To Prevent Users From clicking a button multiple times, multiple form submission operations are performed. Some buttons need to be clicked to make them unavailable.

The Code is as follows: Copy code

<Html>
<Head>
<Title> terms of consent </title>
</Head>
<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
<Input type = "submit" name = "Submit" value = "agree"/>
</Form>
<Script language = "javascript">
Document. form1.Submit. disabled = true;
Var wait = 9; // stay time
Function updateinfo (){
If (wait = 0 ){
Document. form1.Submit. value = "I agree ";
Document. form1.Submit. disabled = false;
}
Else {
Document. form1.Submit. value = "read terms" + wait;
Wait --;
Window. setTimeout ("updateinfo ()", 1000 );
}
}
Updateinfo ();
</Script>
</Body>
</Html>

Whether the setting button is available or not. The "disabled" attribute is used.

Example: w3cschool

The Code is as follows: Copy code

<Html>
<Head>
<Script type = "text/javascript">
Function disable ()
{
Document. getElementById ('txt1'). disabled = true;
}
Function enable ()
{
Document. getElementById ('txt1'). disabled = false;
}
</Script>
</Head>
<Body>

<Textarea id = "txt1">
Hello world... This is a text area
</Textarea>
<Br/>
<Input type = "button" onclick = "disable ()" value = "Disable"/>
<Input type = "button" onclick = "enable ()" value = "Enable"/>

</Body>
</Html>

Conclusion,

The above three instances are all set based on the disabled attribute of the input, so that the disabled attribute is set at the end of both click and use definition control.

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.