gpt4 book ai didi

php - bootstrap-4 表单在提交后删除验证

转载 作者:行者123 更新时间:2023-12-05 00:39:54 25 4
gpt4 key购买 nike

提交后我无法删除验证,成功消息后也会显示验证。

我尝试在成功提交所有输入字段并删除后提交,但验证保持不变,它显示每个输入字段的验证图标。

$('#formid').on('submit', function(e) {

// if the validator does not prevent form submit
if (!e.isDefaultPrevented()) {
var url = "process.php";

// POST values in the background the the script URL
$.ajax({
type: "POST",
url: url,
data: $(this).serialize(),
success: function(data) {
var messageAlert = 'alert-' + data.type;
var messageText = data.message;
// let's compose Bootstrap alert box HTML
var alertBox = '<div class="alert ' + messageAlert + 'alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';
if (messageAlert && messageText) {

$('#formid').find('.messages').html(alertBox);
$('#formid').resetForm();
$('#formid')[0].reset();

}
}
});
return false;
}
});

最佳答案

删除 .was-validated来自 <form> 的类(class)将隐藏验证。

https://getbootstrap.com/docs/4.0/components/forms/#validation

Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form>. Otherwise, any required field without a value shows up as invalid on page load. This way, you may choose when to activate them (typically after form submission is attempted).

关于php - bootstrap-4 表单在提交后删除验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54129580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com