【问题标题】:SweetAlert 2 button cancel submitting formSweetAlert 2 按钮取消提交表单
【发布时间】:2020-07-15 08:51:02
【问题描述】:

即使我在第一个警报上单击取消按钮,也会显示第二个警报。如果我单击取消按钮,我希望关闭警报

$('#tblUser tbody').on('click','.reset',function(){ 
       Swal.fire({
          title: 'Reset password?',
          text: "",
          icon: 'question',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Yes'
       }).then(() => {
         Swal.fire(
             'Reset!',
             'Your password has been reset.',
             'success'
       ).then((result)=>{
            if(result.value){
                 $(this).closest('form').submit();
            } 
       });
    })
  });
});

【问题讨论】:

    标签: javascript jquery laravel sweetalert sweetalert2


    【解决方案1】:

    你需要检查用户输入的是yes还是cancel,所以这里需要检查标志条件..

    $('#tblUser tbody').on('click','.reset',function(){ 
           Swal.fire({
              title: 'Reset password?',
              text: "",
              icon: 'question',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Yes'
           }).then((result) => {
              if(result.value) {
                   Swal.fire(
                      'Reset!',
                      'Your password has been reset.',
                      'success'
                   ).then((result)=>{
                       if(result.value){
                          $(this).closest('form').submit();
                       } 
                   });
               }
        });
      });
    });
    

    【讨论】:

    • 您的代码有错误,先生,我的数据表上的数据没有显示,但感谢您的回复,我已经解决了
    【解决方案2】:
    $('#tblUser tbody').on('click','.reset',function(){ 
    Swal.fire({
      title: 'Reset password?',
      text: "",
      icon: 'question',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Yes'
    }).then((result) => {
    if(result.value){
    Swal.fire(
      'Reset!',
      'Your password has been reset.',
      'success'
    ).then(()=>{
      $(this).closest('form').submit();
    });
    } })});
    });
    

    【讨论】:

      猜你喜欢
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 2022-01-24
      相关资源
      最近更新 更多