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.