Bootbox是一个很小的jQuery插件,用于使用Twitter的引导框架创建警报、确认和灵活的对话框。
目前使用最新的Bootstrap 5、Bootstrap 4和Bootstrap 3框架。
该库公开了三种旨在模仿其原生JavaScript等价物的方法。它们的确切方法签名是灵活的,因为每个方法签名都可以使用各种参数来自定义标签和指定默认值,但它们最常见的名称是这样的:
1.包括jQuery库和Bootbox.js插件的文件。
- <script src="/path/to/jquery.min.js"></script>
- <!-- Bootbox Without Locals -->
- <script src="dist/bootbox.min.js"></script>
- <!-- Locals -->
- <script src="dist/bootbox.locales.min.js"></script>
- <!-- Bootbox With Locals -->
- <script src="dist/bootbox.all.min.js"></script>
2.包括最新的Bootstrap框架。
- <link rel="stylesheet" href="/path/to/bootstrap.min.css">
- <script src="/path/to/bootstrap.min.js"></script>
3.创建一个警报弹出框。
- bootbox.alert("Alert!", function(){
- // optional callback
- });
- // or
- bootbox.alert({
- size: "small",
- title: "Dialog Title",
- message: "Your message hereâ¦",
- callback: function(){}
- })
4.创建一个确认弹出框。
- bootbox.confirm("Are you sure?", function(result){
- alert('confirmed')
- })
- // or
- bootbox.confirm({
- size: "small",
- message: "Are you sure?",
- callback: function(result){
- alert('confirmed')
- }
- })
5.创建一个提示弹出框。
- bootbox.prompt("What is your name?", function(result){
- // do something
- })
- // or
- bootbox.prompt({
- value: '', // initial value
- inputType: 'input', // any form elements
- inputOptions: {},
- min: null, // min value
- max: null, // max value
- step: null, // step size
- maxlength: null, // max length
- pattern: '', // require the input value to follow a specific format
- placeholder: '',
- required: true, // if is required
- multiple: false, // allows users to select more than one option when using the select input type
- size: "small",
- title: "What is your name?",
- callback: function(result){
- // result = String containing user input if OK clicked or null if Cancel clicked
- }
- })
6.创建一个自定义弹出框。
- bootbox.dialog({
- message: 'HTML content here',
- // more options here
- })
7.具有默认值的全局选项。
- bootbox.dialog({
- // dialog message
- message: 'HTML content here',
- // title
- title: 'dialog title',
- // shows the dialog immediately
- show: true,
- // default language
- locale: 'en',
- // dialog container
- container: 'body',
- // default value (used by the prompt helper)
- value: '',
- // default input type (used by the prompt helper)
- inputType: 'text',
- // enables backdrop or not
- backdrop: null,
- // shows close button
- closeButton: true,
- // enables animations or not
- animate: true,
- // extra CSS class
- className: null,
- // dialog size
- size: 'small',
- // flips the order in which the buttons are rendered, from cancel/confirm to confirm/cancel
- swapButtonOrder: false,
- // adds the the modal-dialog-centered to the doalog
- centerVertical: false,
- // Append "multiple" property to the select when using the "prompt" helper
- multiple: false,
- // Automatically scroll modal content when height exceeds viewport height
- scrollable: false
- // dismisses the dialog by hitting ESC
- onEscape: true,
- // custom action buttons
- buttons: {},
- // callback
- callback: function(){},
- // the element that triggered the dialog opening
- relatedTarget: null,
- })
8.该插件还支持超过42个本地插件。
- bootbox.dialog({
- locale: 'en'
- })
9.确定弹出框是否可重复使用。默认值:false。
- bootbox.dialog({
- // whether or not to destroy the modal on hide
- reusable: false
- })
10.API方法。
- // sets options
- bootbox.setDefaults({
- // options here
- });
- // sets local
- bootbox.setLocale('en');
- // adds local
- bootbox.addLocale(String name, object values);
- // removes local
- bootbox.removeLocale(String name);
- // hides all dialog boxes
- bootbox.hideAll();
版本6.0.0(2023-02-10)
版本6.0.0(2022-11-27)
v.5.3版本(2022-04-28)
v.5.2版本(2020-11-30)
第5.1版(2020-10-11)
版本4.1(2020-09-29)
版本5.0.0(2020-01-08)
第3.2版(2019-11-04)
v.3.2(2019年8月21日)
v.2.0版本(2019-07-14)
v1.3版本(2019-05-07)
v5.1.2(2019年4月19日)
v.1.1(2019年4月15日)
v5.0.0版本(2019-04-04)
v5.0.0版本(2019-02-28)
2018-03-22
v4.4.0版(2017-09-05)
第3.2.0版(2013-04-09)