有没有可能将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”?由于它现在指的是bootbox,所以“foo”返回undefined。
var Foo = $(this).attr('id');
,但是当我在回调函数中引用Foo
时,它是未定义的。 - LBF