$( 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值?
答案 0 :(得分:2)
如果那是你正在寻找的东西,我不是不舒服但是我会建议你去引导网站 http://getbootstrap.com/css/
你会发现一个交叉删除按钮:
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
和关闭按钮,可能就是你要找的东西:
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>