jquery 中禁止表单多次提交
在jquery 中,防止提交多次表单其实是很简单的,代码如下:
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <title>Safe submit with jQuery</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#submit").click(function( $(":input").attr("disabled", true); var dataString = 'name=test'; $.ajax({ type: "POST", url: "1.php", data: dataString, success: function(){ $(":input").removeAttr('disabled'); } }); return false; }); }); </script> </head> <body> <form> Name:<input type="test" name="name" id="name" /> <input type="submit" name="submit" id="submit" /> </form> </body></html>