JS control button is available after clicking on the instance

Source: Internet
Author: User

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.

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.