【问题标题】:multiple jQuery validation bootstrap plugin do not validate multiple forms多个 jQuery 验证引导插件不验证多个表单
【发布时间】:2015-02-04 11:05:11
【问题描述】:

我在单个引导页面上遇到了 2 个似乎无法验证的表单。每个表单都使用不同的验证,但由于我没有在我的 .js 文件中指出任何特定的表单 ID,因此第一个 .js 文件将应用于每个表单。我正在努力让每个 .js 验证文件应用于正确的表单。

在我的 index.html 页面上,我有类似的内容:

<form name="sentMessage" id="contactForm" novalidate>
...
<form name="sentOrder" id="orderForm" novalidate>
...
<script src="js/jqBootstrapValidation.js"></script>
<script src="js/contact.js"></script>
<script src="js/order.js"></script>

每个 .js 文件如下所示:

$(function() {

$("input,textarea").jqBootstrapValidation({
    preventSubmit: true,
    submitError: function($form, event, errors) {
        // additional error messages or events
    },
    submitSuccess: function($form, event) {
        event.preventDefault(); // prevent default submit behaviour
        // get values from FORM
        var nameSender = $("input#orderNameSender").val();

如果我尝试 $("#orderForm").(function() 和 $("#contactForm")(function() 它不起作用。在此先感谢您的帮助!

【问题讨论】:

  • 尝试使用一些类$(".testStack").jqBootstrapValidation({&lt;form name="sentOrder" id="orderForm" class="testStack" novalidate&gt;
  • 谢谢你,Ethaan,但这也没有用。不添加任何内容的行为会提交表单,但始终使用调用的第一个 .js 文件。添加 class 或 id 会阻止提交表单,单击提交按钮也会使焦点回到页面顶部。

标签: javascript jquery twitter-bootstrap


【解决方案1】:

.find 可能会起作用。

$(function(){
        $("#contactForm").find('textarea,input').jqBootstrapValidation({
             //jqBootstrapValidation CODE
        });
    });

【讨论】:

  • 太棒了,成功了。感谢您的帮助,非常感谢您准确而快速的回答。
猜你喜欢
  • 2014-05-14
  • 2015-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
  • 2018-12-28
相关资源
最近更新 更多