试图绑定某些事件以接触WordPress的表单7,但事件从未被调用。参考(联系表7 Ajax回调)
这是我的约束力:
$('.wpcf7').on('invalid.wpcf7 spam.wpcf7 mailsent.wpcf7 mailfailed.wpcf7 submit.wpcf7'), function () {
sb[9].tinyscrollbar_update('relative');
console.log('invalid');
}
console.log
从未被调用。我正在绑定所有用于测试的事件,还是我将其绑定错误?
这对我有用:
jQuery(document).on('wpcf7:submit', function () {
jQuery('#formAlerts').modal();
});
jQuery( document ).ajaxComplete(function( event,request, settings ) {
var alertMessage = $(".wpcf7-response-output").html();
jQuery(document).find("#formResponse").html(alertMessage);
function sample() {
if(jQuery('.wpcf7-form.invalid').length > 0){
}else{
jQuery('#formAlerts').modal('hide');
}
}
setTimeout(sample, 2000);
});
该事件不在WPCF7元素上,而是在文档本身上。
$(document).on('mailsent.wpcf7', function(event) {
console.log(event)
})
编辑:从您的链接中查看了最佳答案后,以上是我得到的方式,对我来说很好。
编辑2:看起来链接的顶部答案中的事件是使用不同的事件,这些事件可能会从形式容器中推动,而您试图使用的事件看起来像从文档绑定的事件。