When using AJAX to request data asynchronously, we need to disable the request Submission button in order to avoid the user clicking the button multiple times for some reason and submitting a duplicate request.
Focus: jquery's attr and removeattr two functions, primarily the disabled attribute of the element button.
Demo:
Copy Code code as follows:
<body>
<a class= "Disabled" >button disabeld</a> <a class= "abled" >button abled</a><br/><br/ >
<input type= "button" id= "Submit" name= "submit" value= "Submit" >
</body>
<script type= "Text/javascript" src= ". /jquery-1.2.6.js "></script>
<script type= "Text/javascript" >
$ (function () {
Make it ineffective
$ (". Disabled"). Click (function () {
$ ("#submit"). attr ("Disabled", "disabled");
$ ("#submit"). Val (' disabled ... ');
});
Activated
$ (". abled"). Click (function () {
$ ("#submit"). Removeattr ("Disabled");
$ ("#submit"). Val (' Submit ');
});
Action Request
$ ("#submit"). Click (function () {
$ ("#submit"). attr ("Disabled", "disabled");
Alert ("HI");//send Ajax Request
$ ("#submit"). Removeattr ("Disabled");
});
});
</script>
Description: When clicking Button Disabeld, use $ ("#submit"). attr ("Disabled", "disabled") to disable the test button, in essence, add a disabled property to the Test button, and then click button Abled "or execute the Send Ajax () request, when the request is complete, use $ (" #submit "). Removeattr (" Disabled "); The statement removes the Disable button properties, thereby enabling the disabled button to avoid duplicate requests.