sweetalert:如何将参数传递给回调

2024-03-17

我正在使用 javascript 警报库甜蜜警报 http://t4t5.github.io/sweetalert/

我的代码是:

function foo(id) {
    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(){
      swal("Deleted!", "Your imaginary file has been deleted.", "success");
    });
}

我怎样才能通过id from foo()swal 中的回调函数的函数?


function(id){
  alert(MyId);
  swal("Deleted!", "Your imaginary file has been deleted.", "success");
});

这是行不通的,因为在这种情况下id是选项是确认对于您的确认对话框 - 请参阅SweetAlert 文档 http://t4t5.github.io/sweetalert/.

这将起作用 - 不需要额外的变量:

function foo(id) {
  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){
    alert(isConfirm);
    alert(id);
    swal("Deleted!", "Your imaginary file has been deleted.", "success");
  }); 
} 
foo(10);

这里是jsfiddle:http://jsfiddle.net/60bLyy2k/ http://jsfiddle.net/60bLyy2k/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

sweetalert:如何将参数传递给回调 的相关文章

随机推荐