gpt4 book ai didi

javascript - 当提交按钮在表单之外时,如何使用 Bootstrap 3 表单验证?

转载 作者:数据小太阳 更新时间:2023-10-29 04:31:03 25 4
gpt4 key购买 nike

我对表单验证的 Bootstrap 3 实现感到困惑。我是 Bootstrap 的新手,我似乎无法使用不包含提交按钮的表单进行表单验证。可以使用以下代码查看我正在寻找的表单验证类型:

http://jsfiddle.net/hTPY7/1107/

<form>
<div class="form-group">
<label class="control-label" for="username">Email:</label>
<div class="input-group">
<input class="form-control" placeholder="Email" name="email" type="email" required />
</div>
</div>

<div class="form-group">
<label class="control-label" for="password">Password:</label>
<div class="input-group">
<input class="form-control" type="password" placeholder="Password" name="lastname" type="text" required />
</div>
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>

我知道我可以像下面的代码一样使用一些 JQuery 提交表单,但是我如何使用 Bootstrap 3 验证?

$( "#createUserSubmit" ).click(function() {
$( "#newUserForm" ).submit();
});

多年来我一直在阅读 Stackoverflow,但这是我的第一篇文章。我四处寻找答案,但我能找到的只是使用其他验证库的解决方案。我想使用 Bootstrap 自己的内置函数。

谢谢!

最佳答案

我做了一些研究,现在我知道我看到的表单验证不是 Bootstrap 的功能,而是新的 CSS3/HTML5 功能。我认为除非提交按钮包含在表单中,否则不可能(没有 JS)执行此表单验证。这是不起作用的示例:

http://jsfiddle.net/hTPY7/1112/

这是一个如何修复它的例子:

http://jsfiddle.net/hTPY7/1113/

<form>元素不仅需要包围表单,还需要包围 Bootstrap 模态 div。

这是另一篇很好地总结了我的问题的帖子:

HTML5 form validation for AJAX button submit

关于javascript - 当提交按钮在表单之外时,如何使用 Bootstrap 3 表单验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23595416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com