Met*_*lik 6 javascript 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");
});
}
Run Code Online (Sandbox Code Playgroud)
如何在swal中id从foo()函数传递回调函数?
function(id){
alert(MyId);
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为在这种情况下,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);
Run Code Online (Sandbox Code Playgroud)
这里是jsfiddle:http://jsfiddle.net/60bLyy2k/
| 归档时间: |
|
| 查看次数: |
17287 次 |
| 最近记录: |