Submit a form with jQuery / Javascript without ign

2019-07-05 23:52发布

问题:

so I have the following form:

    <form action="register.php" method="post" id="register-form" name="register-form">
    <input type="text" id="username" name="username" placeholder="Username" autofocus="autofocus" required />
    <input type="text" id="password" name="password" placeholder="Password" required />
    <a href="javascript:void(0);" class="btn" onclick="$('#register-form').submit();">Register</a>
    <input type="submit" style="display: none;" />
    </form>

What I want to know, is there a way to make jQuery take care of the "required" tag when submitting a form? Right now it doesn't.

回答1:

Trigger click on the submit button instead.

http://jsfiddle.net/PdUcq/



回答2:

From this link,

required attribute works in most new browsers. In older browsers its not supported since its part of the HTML5 spec.

If you are looking for cross browser support with jquery you would have to use some plugin. One of the good ones is this plugin.

Or you can go ahead and write your own custom validators, but why re-invent the wheel.