【发布时间】:2016-05-02 19:42:49
【问题描述】:
我在 bootbox v3 文档中看到您可以使用以下方法更改标签 bootbox.alert(str message, str label, fn callback) 自定义按钮文本,关闭时调用回调,
但是在 4.4 版这个方法似乎不起作用,我怎样才能在警报消息上使用自定义按钮标签
【问题讨论】:
标签: javascript jquery angularjs popup bootbox
我在 bootbox v3 文档中看到您可以使用以下方法更改标签 bootbox.alert(str message, str label, fn callback) 自定义按钮文本,关闭时调用回调,
但是在 4.4 版这个方法似乎不起作用,我怎样才能在警报消息上使用自定义按钮标签
【问题讨论】:
标签: javascript jquery angularjs popup bootbox
您可以使用buttons 选项覆盖任何对话框的文本(这需要您使用选项对象来设置对话框)。例如,这是一个自定义警报:
$(function() {
bootbox.alert({
message: 'I have a custom OK button',
buttons: {
ok: {
label: 'Right on!'
}
}
})
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
对于确认和提示,您可以将confirm 和cancel 覆盖为按钮。
【讨论】:
你可以试试这样的:
bootbox.alert({
size: 'small',
message: "Your message here…",
callback: function(){ /* your callback code */ }
}).init(function(){
$('.btn.btn-primary').text('Custom Text')
});
来自文档:
bootbox.init(function): Allows the user to supply a function to be called when dialog gets initialized.http://bootboxjs.com/documentation.html#bb-public-methods
【讨论】: