2015-04-17 40 views
0
$(document).ready(function() { 

$("#login-link").on("click", function() { 
$("#login-modal").modal("show"); 

}); 

$('#loginform') 
    .bootstrapValidator({ 
    excluded: ':disabled', 
    feedbackIcons: { 
     valid: 'glyphicon glyphicon-ok', 
     invalid: 'glyphicon glyphicon-remove', 
     validating: 'glyphicon glyphicon-refresh' 
    }, 
    fields: { 
     username: { 
      validators: { 
       notEmpty: { 
        message: 'The username is required' 
       } 
      } 
     }, 
     password: { 
      validators: { 
       notEmpty: { 
        message: 'The password is required' 
       } 
      } 
     } 
    } 
}) 
    .on('success.form.bv', function (e) { 
    // Prevent form submission 
    e.preventDefault(); 


     // Get the form instance 
     var $form = $(e.target); 

     // Get the BootstrapValidator instance 
     var bv = $form.data('bootstrapValidator'); 

     // Use Ajax to submit form data 
     $.post($form.attr('action'), $form.serialize(), function(result) { 

      if(result=="success") 
      { 
      window.location = "home.php"; 
      } 
      else 
      { 
      alert("wrong username or password"); 
      } 
     }, 'json'); 



    $('#login-modal').modal('hide'); 
}); 

$('#login-modal') 
    .on('shown.bs.modal', function() { 
     $('#loginform').find('[name="username"]').focus(); 
    }) 
    .on('hidden.bs.modal', function() { 
     $('#loginform').bootstrapValidator('resetForm', true); 
    }); 
    }); 

這是我的代碼的一部分。這裏如何在bootstrapvalidation插件中按下取消按鈕時關閉模式,以及如何清除bootstrapvalidation插件中的formfild值?如何在自舉驗證中按下取消按鈕時隱藏模式

回答

2

我不是舒爾如果這是你在找什麼,但anywhay我會建議去引導網站 http://getbootstrap.com/css/

在那裏你會找到一個交叉刪除按鈕:

<button type="button" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button> 

和這個關閉按鈕,可能是你要找的東西:

<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
+0

多數民衆贊成在ok.this我知道它。我想要的是..我有2個按鈕在模態內的形式,當我按取消模型應該關閉,當我按提交表單應提交,如果它包含任何錯誤,它應該驗證。但現在如果我按取消也驗證工作,而不是這個模態應該關閉 – vinay

+0

謝謝。第二個爲我工作..數據 - 解僱 – vinay

+0

你能比請提交我的答案:) – Joh

相關問題