Yii2 使用 bootboxJS美化confirm窗口
有些关键操作比如删除,我们在执行前一般先弹出来个confirm确认窗口。
在Yii2中为一个操作添加confirm确认很容易。只需在链接出添加一个‘data-confirm' => '确实要添加?'属性。
Html::a('<i class="fa fa-plus"></i> 添加', ['create'],
[
'class' => 'btn btn-success btn-sm',
'data-confirm' => '确实要添加?'
]);

玄机隐藏在yii.js
美中不足的是,yii使用的是原生的confirm,有点丑。如果能使用bootboxJS提供的bootstrap样式的弹窗会更好看些。

实现起来也很容易,bootbox本身就一个js文件,只需引入进来,然后覆盖yii提供的conform方法即可。
先下载最新的bootbox.min.js文件,我是放到了\backend\web\js
新建一个BootboxjsAsset.php文件
<?php
/**
* Created by PhpStorm.
* User: mafeifan
* Date: 2016/06/04
* Time: 20:23
*/ namespace backend\assets; use yii;
use yii\web\AssetBundle; class BootboxjsAsset extends AssetBundle
{ public $sourcePath = '@backend/web/';
public $js = [
'js/bootbox.min.js',
];
public $depends = [
'yii\web\YiiAsset',
'backend\assets\BootstrapAsset',
]; public static function overrideSystemConfirm()
{
Yii::$app->view->registerJs('
yii.confirm = function(message, ok, cancel) {
bootbox.confirm(message, function(result) {
if (result) { !ok || ok(); } else { !cancel || cancel(); }
});
}
');
}
}
注意命名空间和bootbox.min.js的位置。
因为我想在后台全局覆盖confirm弹窗。
打开backend\views\layouts\main.php。添加如下代码。
use backend\assets\AppAsset;
use backend\assets\BootboxjsAsset;
AppAsset::register($this);
BootboxjsAsset::register($this);
BootboxjsAsset::overrideSystemConfirm();
大功告成,快试试效果吧。
PS : 覆盖的js代码是写在php文件中,也可写在js文件中。
参考:http://qiita.com/tanakahisateru/items/be28b7bed4566ce8fa99
Yii2 使用 bootboxJS美化confirm窗口的更多相关文章
- Yii2美化confirm
在view中, <?= Html::a('删除', ['post/delete', 'id' => $post['id']],['data-confirm'=>'确定要删除吗?']) ...
- 浅谈Winform控件开发(一):使用GDI+美化基础窗口
写在前面: 本系列随笔将作为我对于winform控件开发的心得总结,方便对一些读者在GDI+.winform等技术方面进行一个入门级的讲解,抛砖引玉. 别问为什么不用WPF,为什么不用QT.问就是懒, ...
- Yii2.0 URL美化
1. 程序初始化注册文件,加入如下: 'urlManager' =>[ 'class' => 'yii\web\UrlManager', 'showScriptName' =>fal ...
- yii2.0 路由美化以及自定义设置
在配置文件里修改: 如果把'enablePrettyUrl' => true,设为true那么你的gii就访问不到: 'rules' => [ '<c ...
- yii2.0 url美化-apache服务器
//配置内容 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => false, //不启用严格 ...
- [路由] -- Yii2 url地址美化与重写
转载:http://blog.csdn.net/lmjy102/article/details/53857520
- Yii2.0 URL美化功能Nginx与Apache配置文件
NGinx: location / { index index.html index.htm index.php; try_files $uri $uri/ /index.php$is_args$ar ...
- Yii2实现即可以美化路由访问又可以原始路由访问
1. 本地环境 nginx version: nginx/1.11.1 PHP 7.1.0-dev (cli) mysql Ver 14.14 Distrib 5.7.22, for Linux (x ...
- 修改js confirm alert 提示框文字的简单实例
修改js confirm alert 提示框文字的简单实例: <!DOCTYPE html> <html> <head lang="en"> & ...
随机推荐
- 108.UIView关于布局和约束的方法(AutoLayout)
http://blog.csdn.net/wangyanchang21/article/details/52270136 关于布局(UIViewHierarchy) 1.layoutSubviews ...
- POJ2720 Last Digits
嘟嘟嘟 一道题又写了近两个点-- 这道题直接暴力快速幂肯定会爆(别想高精),所以还是要用一点数学知识的- 有一个东西叫欧拉降幂公式,就是: \(x ^ y \equiv x ^ {y \ \ ...
- SpringBoot实战(七)之与Redis进行消息传递
此次教程演示安装的是Window版的Redis, Linux安装Redis可以参考我的这篇博文:Redis的安装和客户端使用注意事项 关于Java连接Redis操作方面可以参考我的这篇博文:Java连 ...
- spring boot实战(第二篇)事件监听
http://blog.csdn.net/liaokailin/article/details/48186331 前言 spring boot在启动过程中增加事件监听机制,为用户功能拓展提供极大的便利 ...
- [译] MVP模式的14条规则
笔者在前文<MVP和MVC>中提到了两者的区别,以及MVP日趋流行的原因:即随着各种给力UI框架的发布,View的功能越来越强,已经足以完成一些简单的不需要与后台或其他view交互的eve ...
- Blocking Master Example QT 自带 的 serial 即 串口 例子
1.官方解释文档:http://doc.qt.io/qt-5/qtserialport-blockingmaster-example.html Blocking Master shows how to ...
- SpringBoot两种读取配置文件的方式
方式一 @Value("${custom.group}") private String customGroup; 方式二 @Autowired private Environme ...
- 网络的可靠性nyoj170
网络的可靠性 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 A公司是全球依靠的互联网解决方案提供商,也是2010年世博会的高级赞助商.它将提供先进的网络协作技术,展 ...
- Linux安装部署
Linux桌面发行版 UbuntuCentOSRed heat LinuxOracle Linux 一.系统安装 1.系统分区 若手动分区swap和根分区必须创建,推荐创建boot分区. /----- ...
- Delphi Compiler Bug?
I found a Bug of Delphi XE3 Compiler,It may exists in XE4,XE5. Here is the code to show the bug proc ...