HTML5需要和jQuery的提交() [英] html5 required and jquery submit()

查看:114
本文介绍了HTML5需要和jQuery的提交()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将html5实现为一个表单,但是当我通过jquery提交表单并尝试使用html5required属性时,我遇到了一个问题。

I'm trying to implement html5 into a form, but I came with a problem when I submit the form through jquery and try to use the html5 "required" attribute.

这是我的表单,非常简单:

Here is my form, quite simple:

<form action="index.php" id="loginform">
      <input name="username" required placeholder="username" type="text">    
      <a href="javascript:$('#loginform').submit();">Login</a>
</form>

问题是当表单通过jquery提交时,它只是绕过了必需的属性。我知道只有表单是由用户提交的,而不是脚本才能使用required,所以当我将锚点更改为提交输入时,它的工作非常完美。

The problem is that when the form is submited through jquery, It just by-passes the required attribute. I know that required should only work if the form is submitted by the user, not by a script, so when I change the anchor to a submit input it works perfect.

我的观点是,如果有办法强制jquery .submit()使用html5必需的属性。

My point is if there is a way to force the jquery .submit() to use html5 required atribute.

提前感谢您的回答

推荐答案

我做了以下内容:

I did the following

<form>
    ...
    <button type="submit" class="hide"></button>
</form>

<script>
    ...
    $(...).find('[type="submit"]').trigger('click');
    ...
</script>

它可以工作!

这篇关于HTML5需要和jQuery的提交()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆