Block all submit buttons until the page is fully loaded.

Can I learn how to use jquery to block everything <input type="submit/button" ..and only allow sending when the page is fully displayed?

+5
source share
5 answers

Because of the use case, I could do otherwise. Instead of actually disabling the buttons, I would simply not allow the submit action to work until the page is loaded. This does not require any changes to existing HTML to work, and your pages will not be useless when disabling JS:

<script>
   // Keep all submit buttons from working
   $('input:submit').live('click', function () {
      return false;
   });

   // After everything loads, remove the restriction
   $(window).load(function(){
       $('input:submit').die();
   });
</script>

: , script jQuery <head>, , . (, ).

+10

, disabled true:

<input type="submit" disabled="disabled" /> 

, , :

$('input').removeAttr('disabled');
+5

JQuery

$(document).ready(function(){
  $(":button,:submit").removeAttr("disabled");  
});

HTML

<input type="button" id="button1" value="Button 1" disabled="disabled">
<input type="button" id="button2" value="Button 2" disabled="disabled">
<input type="button" id="button3" value="Button 3" disabled="disabled">
<input type="submit" id="submit" value="Submit" disabled="disabled">
+2
<input id="form-submit" type="submit" disabled="disabled" value="Submit" />

$(document).ready(function() {
    $("#form-submit").removeAttr('disabled');
});
+1

-

window.onsubmit=function(){return false;}
window.onload=function(){window.onsubmit='';}

, onsubmit. . , jquery, , .

0

All Articles