【问题标题】:1000hz bootstrap validator data-toggle="validator" not working1000hz 引导验证器 data-toggle="validator" 不工作
【发布时间】:2016-05-19 05:22:04
【问题描述】:

我正在尝试使用以下验证器 http://1000hz.github.io/bootstrap-validator/ 来验证以下表单-toggle="validator" 它说它应该自动验证它。我也尝试使用底部的脚本。有人可以告诉我如何使用它的示例。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="dist/css/bootstrap.min.css" rel="stylesheet">
  </head>
   <body>
         <script src="js/bootstrap.min.js"></script>
         <script src="dist/js/bootstrap.min.js"></script>
         <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.9.0/validator.min.js"></script>
         <h1>Register Below! </h1>

      <form data-toggle="validator" role="form" method="post" class="form-horizontal" name="myForm">
            <div class="form-group">
              <label for="inputName" class="col-md-3 control-label">Name</label>
            <div class="col-md-6">
             <input type="text" class="form-control" id="inputName" name="name" placeholder="Username" required />
           </div>
          </div>


           <div class="form-group">
            <label for="inputEmail" class="col-md-3 control-label">Email</label>
           <div class="col-md-6">
            <input type="email" class="form-control" id="inputEmail" name="email" placeholder="Email" data-error="Incorrect email address" required>
           <div class="help-block with-errors"></div>
          </div>
          </div>
          <div class="form-group">
            <label for="inputPassword" class="col-md-3 control-label">Password</label>
          <div class="form-group col-sm-6">
            <input type="password" data-minlength="6" class="form-control" id="inputPassword" name="password" placeholder="Password" required>
          <span class="help-block">Minimum of 6 characters</span>
          </div>
          </div>
          <div class="form-group">
            <label for="inputPassword" class="col-md-3 control-label">Confirm Password</label>
          <div class="form-group col-sm-6">
            <input type="password" class="form-control" id="inputPasswordConfirm" data-match="#inputPassword" data-match-error="The password doesnt match" placeholder="Confirm" required>
          <div class="help-block with-errors"></div>
         </div>
        </div>
        <div class="form-group">
        <div class="col-md-9 col-md-offset-3">
          <button type="submit" name="submit" class="btn btn-primary">Register</button>
       </div>
    </div>
   </form>

        <script >
          (document).ready(function() {
           $('#myForm').validator()
             $('#myForm').submit(function (e) {
                 $('#myForm').validator('validate')
              });
           });

         </script>
    </body>
</html>

【问题讨论】:

    标签: javascript jquery twitter-bootstrap validation bootstrapvalidator


    【解决方案1】:

    你的方法中的几个错误

    1. 不包含 jQuery 库(必须包含在所有其他 JS 库之上)
    2. bootstrap.min.js 包含两次(删除一次)
    3. 在脚本中 (document).ready(function() 之前缺少 $
    4. &lt;form&gt; 中缺少 id 选择器 myForm

    代码没有问题

    旁注:验证可以使用属性data-toggle="validator" 或通过JS 脚本$('#myForm').validator() 在表单上初始化,两者都不需要。

    Fiddle with data-toggle="validator"

    Fiddle with JS Script

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-31
      • 2014-12-10
      相关资源
      最近更新 更多