Yii2美化confirm
2015-12-18 15:01
465 查看
在view中,
<?= Html::a('删除', ['post/delete', 'id' => $post['id']],['data-confirm'=>'确定要删除吗?']) ?>
会在点击删除是弹出
玄机隐藏在yii.js
美中不足的是,yii使用的是原生的confirm,有点丑
在网上找到了一种解决方案
Bootbox.js,是一个小型的JavaScript库用来创建简单的可编程对话框,基于Bootstrap的Modal(模态框)来创建
下载Bootbox.jshttps://github.com/makeusabrew/bootbox
在@app/web/js/路径下创建一个javascript文件,比如main.js
注册资源包
修改文件:@app/assets/Assets.php
bootbox.js(下载包里的)和main.js(刚才创建的)
刷新以前的页面
<?= Html::a('删除', ['post/delete', 'id' => $post['id']],['data-confirm'=>'确定要删除吗?']) ?>
会在点击删除是弹出
玄机隐藏在yii.js
美中不足的是,yii使用的是原生的confirm,有点丑
在网上找到了一种解决方案
Bootbox.js,是一个小型的JavaScript库用来创建简单的可编程对话框,基于Bootstrap的Modal(模态框)来创建
下载Bootbox.jshttps://github.com/makeusabrew/bootbox
在@app/web/js/路径下创建一个javascript文件,比如main.js
yii.allowAction = function ($e) { var message = $e.data('confirm'); return message === undefined || yii.confirm(message, $e); }; // --- Delete action (bootbox) --- yii.confirm = function (message, ok, cancel) { bootbox.confirm( { message: message, buttons: { confirm: { label: "OK" }, cancel: { label: "Cancel" } }, callback: function (confirmed) { if (confirmed) { !ok || ok(); } else { !cancel || cancel(); } } } ); // confirm will always return false on the first call // to cancel click handler return false; }
注册资源包
修改文件:@app/assets/Assets.php
namespace backend\assets; use yii\web\AssetBundle; class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = ['css/site.css']; // 注册js资源 public $js = ['js/bootbox.js', 'js/main.js']; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; }
bootbox.js(下载包里的)和main.js(刚才创建的)
刷新以前的页面
相关文章推荐
- php中JSON的使用与转换
- PHP统计排行,分页
- php判断爬虫
- PHP rabbitmq
- LAMP环境下不能解析php原因及排查步骤
- Workerman 开源高性能的PHP socket 服务器框架
- php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳
- php 在服务器端开启错误日志记录方法
- yii 操作cookie
- php学习之道:mysql SELECT FOUND_ROWS()与COUNT(*)使用方法差别
- PHP中的traits
- php如何判断是手机访问还是电脑访问
- 使用Laravel发送账号激活邮件
- php导入excel数据
- 关于Laravel的多表查询方法
- php生成迅雷快车QQ旋风下载地址
- RTP协议分析
- windows下的,php环境下,无法运行帝国备份王程序的原因是如下
- 解决ThinkPHP下使用上传插件Uploadify浏览器firefox报302错误的方法
- PHP MYSQL 总结