【问题标题】:SweetAlert2 Confirmation on form submit not working with Codeigniter表单提交上的 SweetAlert2 确认无法与 Codeigniter 一起使用
【发布时间】:2017-05-09 09:37:52
【问题描述】:

我正在尝试在用户使用 CodeIgniter 提交表单之前弹出确认窗口,但触发器/提交部分不起作用。它要求确认,但不提交表单。

我的 HTML:

<?php
echo form_open(site_url("action"), array('id' => "order" , )) ?>
<input type="text" class="form-control" name="anything" value="">
<button type="submit" id="btn-submit" class="btn btn-danger" class="form-control">Submit</button>
<?php echo form_close() ?>

这是 Javascript

$('#btn-submit').on('click',function(e){
e.preventDefault();
var form = $(this).parents('form');
swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
}, function(isConfirm){
  if (isConfirm) form.submit();
});
});

我也尝试过定位/选择表单 ID 而不是按钮,但同样的问题。资源已正确加载。

【问题讨论】:

  • 看来我的版本有误!我会在这里更新。

标签: php jquery sweetalert2


【解决方案1】:

改变它:

var form = $(this).parents('form');

var form = $(this).parent('form');

然后再试一次。

【讨论】:

    【解决方案2】:

    我实际上使用了错误的功能。我在加载 sweetalert2 时使用的函数来自 sweetalert。我从

    更改了代码
    swal({
      {... closeOnConfirm: false},
      function() {
       // Function
      }
    });
    

    swal({
      ...
      showLoaderOnConfirm: true,
      preConfirm: function() {
        //function
    }).then(function() {
      swal('Processing');
    });
    

    它正在工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 2017-07-21
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多