在Bootbox 3.2.0中,我能够使用确认,传递的字符串如下:
bootbox.confirm(
confirm_string,
cancel_string,
yes_string,
function(r) {
if (r) {
//do something
}
}
);
我正在升级到4.1.0,上面的函数调用出错了。
根据Bootbox 4.1.0的文档(http://bootboxjs.com/documentation.html),有两种方法可以调用确认:
bootbox.confirm(str message, fn callback)
bootbox.confirm(object options)
我用消息字符串和回调函数测试了第一种方式,它可以工作。对于第二种方式,我能够传递一个对象如下:
{
message: message_string
callback: function(r) {
//do something
}
}
如何以第二种方式为OK,Cancel按钮传递字符串?
谢谢和问候。
答案 0 :(得分:17)
作为替代方案,这也可以直接使用bootbox.confirm
完成,如下所示:
bootbox.confirm({
buttons: {
confirm: {
label: 'Localized confirm text',
className: 'confirm-button-class'
},
cancel: {
label: 'Localized cancel text',
className: 'cancel-button-class'
}
},
message: 'Your message',
callback: function(result) {
console.log(result);
},
title: "You can also add a title",
});
答案 1 :(得分:9)
或使用本地化 - 选项,更改每个默认值的所有按钮:
bootbox.setDefaults({
/**
* @optional String
* @default: en
* which locale settings to use to translate the three
* standard button labels: OK, CONFIRM, CANCEL
*/
locale: "de"
});
见过:http://bootboxjs.com/documentation.html,"助手方法"
答案 2 :(得分:7)
您可以使用“自定义对话框”(bootbox.dialog
)更改这些字符串。
bootbox.dialog({
message: "Custom message",
title: "Custom title",
buttons: {
danger: {
label: "Custom Cancel",
className: "btn-danger",
callback: function() {
//do something
}
},
main: {
label: "Custom OK",
className: "btn-primary",
callback: function() {
//do something else
}
}
}
});