Usage:
Object.disabled = False | True
1, within the specified time to obtain verification code to prevent multiple access:
The code is as follows |
Copy Code |
<input type= "button" id= "btn" value= "Free access to authentication code"/> <script type= "Text/javascript" > var wait=60; function Time (o) { if (wait = = 0) { O.removeattribute ("Disabled"); O.value= "Free access to verification code"; 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, in order to prevent users to click a button several times, resulting in multiple submission of the form operation. Some buttons need to be clicked to implement an unavailable operation.
The code is as follows |
Copy Code |
<title> Agreement terms </title> <body> <form id= "Form1" Name= "Form1" method= "post" action= "> <input type=" Submit "name=" Submit "value=" Agree "/> </form> br> <script language= "JavaScript" > document.form1.Submit.disabled = true; var wait = 9;//stay time Function Updateinfo () { if (wait = 0) { document.form1.Su Bmit.value = "I agree"; document.form1.Submit.disabled = false; } else{ document.form1.Submit.value = "reading terms" +wait; wait--; window.settimeout ("Updateinfo ()", 1000); } } Updateinfo (); </script> </body> |
The Set button is available or not, and the disabled property is used.
Example: W3cschool
The code is as follows |
Copy Code |
<script type= "Text/javascript" > function Disable () { document.getElementById (' Txt1 '). Disabled=true; } function enable () { document.getElementById (' Txt1 '). Disabled=false; } </script> <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>
|
Summarize
The above three instances are set based on the property disabled of input, so that we set the disabled property at the end, either by clicking or using the definition control.