2015-06-27 24 views
-2

在我的HTML和JavaScript代码中,除提交按钮外,所有的事情都很好地工作,如果没有任何错误表单字段,但它不提交。即使没有不正确的字段,提交按钮在引导验证器中也不起作用

<div class="container"> 
     <div class="panel panel-default"> 
      <div class="panel-heading">Registration</div> 
      <div class="panel-body"> 
       <form id="registration-form" method="post" class="form-horizontal"> 

        <div class="form-group"> 
         <label class="col-md-2 control-label" for="fName">First Name</label> 
         <div class="col-md-4"> 
          <input type="text" class="form-control" id="fName" name="fName" placeholder="First Name"/> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-md-2 control-label" for="lName">Last Name</label> 
         <div class="col-md-4"> 
          <input type="text" class="form-control" id="lName" name="lName" placeholder="Last Name"/> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-md-2 control-label" for="email">E-mail ID</label> 
         <div class="col-md-4"> 
          <input type="text" class="form-control" id="email" name="email" placeholder="Your E-mail address"/> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-md-2 control-label" for="password">Password</label> 
         <div class="col-md-4"> 
          <input type="password" class="form-control" id="password" name="password" placeholder="Password"/> 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-md-2 control-label" for="confirmPasword">Confirm Password</label> 
         <div class="col-md-4"> 
          <input type="password" class="form-control" id="confirmPasword" name="confirmPasword" placeholder="Confirm Password"/> 
         </div> 
        </div> 

        <div class="form-group"> 
         <div class="col-md-6 col-xs-offset-2 "> 
          <button type="submit" class="btn btn-success" name="submit" >Submit</button> 
         </div> 
        </div> 

       </form> 

      </div> 
     </div> 
    </div> 

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script  src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">  </script> 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.min.js"></script> 
    <script src="js/bootstrapValidator.min.js" type="text/javascript">  </script> 
</body> 

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $('#alwaysEnableButtonForm') 
     var validator = $("#registration-form").bootstrapValidator({ 
      feedbackIcons:{ 
       valid:"glyphicon glyphicon-ok", 
       invalid:"glyphicon glyphicon-remove", 
       validating:"glyphicon glyphicon-refresh" 
      }, 
      fields:{ 
       fName:{ 
        message:"First Name is required", 
        validators:{ 
         notEmpty:{ 
          message:"Please provide the First Name" 
         }, 
         stringLength:{ 
          max : 25, 
          message: "The first Name should not be more than 25 characters long"  
         } 
        } 
       }, 
       lName:{ 
        message:"Last Name is required", 
        validators:{ 
         notEmpty:{ 
          message:"Please provide the Last Name" 
         }, 
         stringLength:{ 
          max : 25, 
          message: "The Last Name should not be more than 25 characters long" 
         } 
        } 
       }, 
       email:{ 
        message:"E-mail address is required", 
        validators:{ 
         notEmpty:{ 
          message:"Please an E-mail address" 
         }, 
         stringLength:{ 
          min:6, 
          max:45, 
          message: "E-mail address must be between 6 and 45 characters long" 
         }, 
         emailAddress:{ 
          message:"E-mail address is invalid" 
         } 
        } 
       }, 
       password:{ 
        validators:{ 
         notEmpty:{ 
          message:"Password is required" 
         }, 
         stringLength:{ 
          min:8, 
          message:"Password must be 8 digits long atleast" 
         }, 
         different:{ 
          field:"email", 
          message:"E-mail address and password can not match" 
         } 

        } 
       }, 
       confirmPasword:{ 
        validators:{ 
         notEmpty:{ 
          message:"This field is required" 
         }, 
         identical:{ 
          field:"password", 
          message:"This should must match the first password" 
         } 
        } 
       } 
      } 
     }) 
     .on('success.fields.fv', function(e, data) { 
      if (data.fv.getInvalidFields().length > 0) { // There is invalid field 
       data.fv.disableSubmitButtons(true); 
      } 
     }); 

    }); 
</script> 
+0

我我的手机上,所以我不能测试你的代码,但尝试改变

+0

欢迎来到Stack Overflow!我修正了一些拼写问题,并使代码中的缩进保持一致,这样每个人都可以更轻松地阅读。您的JavaScript控制台中是否有任何内容(错误等)可能对某人有用?展示问题的[JSFiddle](http://jsfiddle.com/)也会非常有帮助。 –

回答