如何将参数传递给回调
sweetalert: how pass argument to callback
我正在使用javascript警报库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
从foo()
函数传递到回调函数?
function(id){
alert(MyId);
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
这将不起作用,因为在这种情况下,id是确认对话框的选项isConfirm -请参阅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/
把你的参数放在局部变量中它们可以在内部函数或集群中访问
function foo(id) {
var MyId = 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(){
alert(MyId);
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
}
foo(10);
这里提琴https://jsfiddle.net/
相关文章:
- 要求未定义JS回调参数
- Axios spread()具有未知数量的回调参数
- 节点回调参数无法断言instanceof Error
- each()-将额外的参数传递给回调参数
- AngularJS tokenWrapper-错误的回调参数
- 如何在 jquery 中将事件作为回调方法传递
- 如何将变量从回调函数传递到函数调用
- 拉斐尔未运行回调参数
- 如何在 $ 中执行异步操作.延迟,然后失败过滤回调并传递回成功链
- 使用 jQuery 回调参数通过 AJAX 调用 PHP 函数
- 将函数的执行同步为 node.js 中的回调参数
- 当第一个函数完成没有回调参数时执行第二个函数
- JavaScript Object Literal“;这个“;关键字jQuery回调参数传递
- 在js的as3回调中传递参数的最佳方式是什么?
- 通过回调函数传递参数
- Javascript __postback():参数传递错误"无效的回发或回调参数"
- 在 expressjs 中的回调之间传递路由参数的最佳方法
- 在事件侦听器中传递回调参数
- 将路由段作为回调参数传递
- React_Redux:在连续回调函数中传递回调参数