Home > Article > Web Front-end > JS method to realize clicking on the check box to turn the button or text box into gray and unavailable_javascript skills
The example in this article describes how to use JS to turn the button or text box into gray and unavailable by clicking on the check box. Share it with everyone for your reference. The details are as follows:
You often don’t see it when registering. If you don’t click to read the registration permission, the submit button is gray and cannot be submitted if it is invalid. You must click it. This JS code implements such a function. Only you click to confirm the submission. , the button below will take effect.
The operation effect is as shown below:
The specific code is as follows:
<html> <head> <title>点击复选框按钮变为不可用</title> </head> <script> var checkobj function agreesubmit(el){ checkobj=el if (document.all||document.getElementById){ for (i=0;i<checkobj.form.length;i++){ var tempobj=checkobj.form.elements[i] if(tempobj.type.toLowerCase()=="submit") tempobj.disabled=!checkobj.checked } } } function defaultagree(el){ if (!document.all && !document.getElementById){ if (window.checkobj && checkobj.checked) return true else{ alert("Please read/accept terms to submit form") return false } } } </script> <body> <form name="agreeform" onSubmit="return defaultagree(this)"> <input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>你确认要提交?</b><br> <input type="Submit" value="我一定要提交" disabled> </form> <script> document.forms.agreeform.agreecheck.checked=false </script> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.