bootbox的使用


1.背景介绍


Bootbox.js是一个小型的JavaScript库,基于 Twitter 的 Bootstrap 开发。它允许你创建使用编程对话框。方便用户快速创建模拟框。

2.知识剖析

该库提供了三个旨在模仿其原生JavaScript等效项的函数。他们的确切的函数名是灵活的,

因此每个可以采取各种参数来定制标签和指定默认值,但它们最基本是这样:

警告框

bootbox.alert(message, callback)

提示框

bootbox.prompt(message, callback)

确认框

bootbox.confirm({title: "提示",message: "这是一个确认按钮的样式!",buttons: {confirm: {label: 'Yes',className: 'btn-success'},cancel: {label: 'No',className: 'btn-danger'}},callback: function (result) {console.log('这是回调函数来确认最终结果: ' + result);}});

这三个函数中的每一个都可以调用第四个公共函数,你也可以使用它来创建自己的自定义对话框:

bootbox.dialog(options)

3.常见问题

bootbox的所有版本都是在Bootstrap和jQuery的基础之上的,因此bootstrap,jQuery和bootbox的版本要对应

4.解决方案


注意脚本引用的顺序

    jQuery

    Bootstrap

    Bootbox

    5.编码实战

    警告框:基本用法

    bootbox.alert("This is the default alert!");

    警告框:带回调

    bootbox.alert("This is an alert with a callback!", function(){console.log('This was logged in the callback!');});

    设置框大小

    bootbox.alert({message: "This is the small alert!",size: 'small'});

    确认框基本用法

    bootbox.confirm("确认信息", function(result){console.log('This was logged in the callback: ' + result);});

    交替按钮

    bootbox.confirm({message: "这是一个确认按钮的样式!",buttons: {confirm: {label: 'Yes',className: 'btn-success'},cancel: {label: 'No',className: 'btn-danger'}},callback: function (result) {console.log('This was logged in the callback: ' + result);}});

    提示框:基本用法

    bootbox.prompt("提示信息", function(result){ console.log(result); });

    日期提示

    bootbox.prompt({title: "这是一个带有日期输入的提示!",inputType: 'date'callback: function (result) {console.log(result);}});

    提示输入密码

    bootbox.prompt({title: "这是一个带有密码输入的提示!",inputType: 'password',callback: function (result) {console.log(result);}});

    电子邮件提示

    bootbox.prompt({title: "这是一个带有电子邮件输入的提示!",inputType: 'email',callback: function (result) {console.log(result);}});

    6.扩展思考

    bootbox弹出框如何设置为中文提示

    7.参考文献

    参考一:Bootbox.js


    最后编辑于
    ©著作权归作者所有,转载或内容合作请联系作者
    平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

    推荐阅读更多精彩内容