是否可以将 jQuery 变量传递到 bootbox.js 确认框?
这是代码:
bootbox.confirm({
message: 'Are you sure you want to remove [productName]?',
callback: function(result) {
console.log(result);
},
title: "You can also add a title",
});
其中“productName”是一个变量,例如:
var productName = $('#product_name').val();
这样的事情可能吗?
更新:感谢下面的回答!
解决这个问题......如果我有这样的事情:
$('#product_name1 a.trash').click(function(event){
event.stopImmediatePropagation();
event.preventDefault();
var foo = $(this).parent().attr('id'); // #product_name1
alert(foo); // correct!
bootbox.confirm({
message: 'Are you sure you want to remove [productName]?',
callback: function(result) {
if (confirmed)
alert(foo); // undefined!
}
}
});
});
如何在回调中重新定义“this”?"foo" 返回 undefined 因为它现在指的是 bootbox。