Is it possible to prevent submit button from submitting until DOM is loaded?
I'm doing form validation using jquery validate plugin. It w开发者_StackOverflow中文版orks great, however if DOM is not fully loaded and you click submit button then the document ignores validation and goes to a page specified in form "action" attribute. Is it possible to prevent submit button from submitting until DOM is loaded?
If you generate your submit button like so:
<input type="submit" id="submit" value="submit" disabled="disabled"/>
Then you can put this in your $(document).ready(
right after the validation plugin has been initialised:
$("#submit").prop("disabled", false);
Demo: http://jsfiddle.net/nZVrs/
You could emit your forms initially with something like:
<form ... onsubmit="return false;">
....
</form>
Then in JavaScript, change the onsubmit
handlers of the forms you want to "activate" when you're ready.
How exactly would anyone manage to submit a form before DOMContentLoaded
is fired? Just curious?
If it was window.onload
we are talking about then I would understand because a page could require some time to load completely (especially if content was not previously cached) but DOMContentLoaded
?
In most cases it fires so fast after the page starts rendering that its almost impossible to be that fast and submit the form.
精彩评论