我使用 bootbox 创建一个对话框,但我希望某些按钮仅在某些条件下显示。
我搜索了很多,但没有发现任何有用的信息..
我这样定义引导箱:
bootbox.dialog({
title: "title",
message: "text",
buttons: {
btn1: {
label: "Button 1",
callback: function () {
/* do something */
}
},
btn2: {
label: "Button 2",
callback: function () {
/* do something */
}
}
});
如何使第二个按钮仅出现 if(condition == true)
?
之后我也尝试像这样删除按钮:
bootbox.dialog({...})
if(!condition) {
$('[data-bb-handler="btn2"]').remove();
}
但没有成功。
任何想法表示赞赏!
问候
最佳答案
只需修改传递到引导箱的按钮对象,如下所示
var buttons = {
btn1: {
label: "Button 1",
callback: function() {
/* do something */
}
},
}
// change here !!!
if (false)
buttons.btn2 = {
label: "Button 2",
callback: function() {
/* do something */
}
}
bootbox.dialog({
title: "title",
message: "text",
buttons: buttons
});
<小时/>
fiddle - http://jsfiddle.net/7x5h91v2/
关于javascript - bootbox.js -> 仅当条件为 true 时才在 bootbox.dialog() 中显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36478641/