我试图显示和隐藏一个联系人表单的提交按钮上的微调。当表单正在提交时,微调器应该显示在按钮上。一旦表单被提交,微调器应该被隐藏。
这是我的提交按钮沿着和微调器跨度:
<div class="d-flex justify-content-center">
<button class="btn btn-medium btn-fancy btn-primary mb-0 ls-wider" type="submit" id="submitButton">
<span class="submitSpinner spinner-border spinner-border-sm me-1"></span> Send Message
</button>
</div>
字符串
这是我使用的AJAX函数:
$(document).ready(function() {
$('.submitSpinner').css('display','none');
$("#contact-form").submit(function(e) {
e.preventDefault();
$('#submitButton').text('Sending Message');
$('.submitSpinner').css('display','inline-block');
var data = {
'name': $('#name').val(),
'email': $('#email').val(),
'phone': $('#phone').val(),
'company': $('#company').val(),
'message': $('#message').val(),
}
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: "/contact/message/send",
data: data,
dataType: "json",
success: function(response) {
// console.log(response);
if (response.status == 400) {
$.each(response.errors, function(key, error) {
$('#contact-alerts').append('<div class="col-12 col-md-9 col-lg-7 alert alert-danger alert-dismissible fade in show" role="alert"><button type="button" class="btn-close line-height-unset" data-bs-dismiss="alert" aria-label="Close"></button>' + error + '</div>')
});
$('.submitSpinner').css('display','none');
} else {
$("#contact-form")[0].reset();
$('#submitButton').text('Send Message');
$('.submitSpinner').css('display','none');
$.magnificPopup.open({
showCloseBtn: true,
items: {
src: '#contact-success'
},
type: 'inline',
fixedContentPos: false,
fixedBgPos: true,
overflowY: 'auto',
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
blackbg: true,
mainClass: 'my-mfp-slide-bottom',
});
}
}
});
});
});
型
1条答案
按热度按时间hc8w905p1#
a)您需要将微调器放在按钮外部
B)最初添加一个类,并在其上应用
dispaly:none
CSS。c)现在使用
.show()
和.hide()
来解决它。工作样品: