jQuery Swal使用防止默认然后触发确认后



我使用sweetalert来触发确认框,然后单击按钮并使用preventDefault。确认后是否有办法删除preventDefault ?我试过触发点击,但它一直打开确认。这是我在下面尝试的:

function delete_all_product( _e ) {
_e.preventDefault();
Swal.fire({
title: 'Are you sure you want change region to '+$(this).val()+'?',
icon: 'info',
confirmButtonText: 'Yes',
showCancelButton: true,
}).then((result) => {
if (result['isConfirmed']){
po.populate_product_slider(); 
$('.product-list-item').remove();
$(this).trigger('click');// this is what I've added but it keeps on reopening the swal because it triggers everytime I click.                              
}
}); 
}
$('input[name="prod_reg"]').click(po.delete_all_product);

以下是我尝试过的。特别感谢CarstenLøvboAndersen提供的逻辑。

function delete_all_product( prevent ) {
if(prevent['data']['prevent'] == true){  
prevent.preventDefault();
Swal.fire({
title: 'Are you sure you want change region to '+$(this).val()+'?',
icon: 'info',
confirmButtonText: 'Yes',
showCancelButton: true,
}).then((result) => {
if (result['isConfirmed']){
prevent['data']['prevent'] = false; // this is to prevent multiple clicks 
$(this).trigger('click', true); 
po.populate_product_slider(); 
$('.product-list-item').remove();
prevent['data']['prevent'] = true; //this is to make the prevent true again for the next click                              
}
}); 
}else{
prevent['data']['prevent'] = false; 
}
}
$('input[name="prod_reg"]').click( {prevent:true}, po.delete_all_product );

相关内容

最新更新