Toastr 简介 jquery toastr 一款轻量级的通知提示框插件。 网页开发中经常会用到提示框,自带的alert样式无法调整,用户体验差。 /static/toastr/toastr.min.css"> <script src=". /static/<em>toastr</em>/<em>toastr</em>.min.js"></script> 注意:导入toastr.min.js文件欠必须要先导入jQuery原生文件 在angular模版中注入依赖 angular.module 开始使用 1.成功提示 toastr.success('Hello world!', 'Toastr fun!'); ? 关闭提示框 toastr.clear([toast]); 获取当前显示的提示框 toastr.active(); 刷新打开的提示框(第二个参数配置超时时间) toastr.refreshTimer
http://www.jq22.com/yanshi476 Command: toastrsuccess toastr.options = { "closeButton": false, "debug
jquery-toastr 消息提醒、播放音频 应用情景,有新的订单生成,后台进行消息提醒并播放音频(这里用到轮询简单实现):下面附代码 1.找到laravel-admin 中的 index.blade.php success: function (res) { console.log(res); if(res.code == 200){ toastr.options.timeOut =120000; // 保存2分钟 toastr.warning(res.msg); // 提示文字 toastr.options.onclick
资源地址 github: https://github.com/CodeSeven/toastr 官网:https://codeseven.github.io/toastr/ cdn 资源地址:https /latest/css/toastr.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/<em>toastr</em>.js/latest/js /<em>toastr</em>.min.js"></script> 2. 调用: <script> toastr.options = { // toastr配置 "closeButton": true, //是否显示关闭按钮 ("错误"); toastr.success("成功") toastr.warning("失败") toastr.info("你好") </script> positionClass
toastr.js可以设置四种提示样式: 成功(success) 错误(error) 提示(info) 警告(warning) toastr环境准备 toastr.js官方文档以及源码 https:// codeseven.github.io/toastr/ 解压后,拷贝其中的 toastr.min.css 和 toastr.min.js 到项目中 在html页面引入引入 toastr.min.css 和 toastr.min.js,还有必不可少的 jquery 库 <link rel="stylesheet" href="/<em>toastr</em>/css/<em>toastr</em>.min.css"> < > 需注意引入的顺序,先toastr.min.css,再jquery.js 最后是toastr.min.js。 ; //错误消息提示,默认背景为浅红色 实现效果,默认在屏幕右上角显示 可以通过toastr.info()方式调用,也可以用toastr‘info’方式调用 toastr['info']
image.png ionic3集成使用ngx-toastr 根据Github上的文档说明,进行如下步骤: 安装组件 npm install ngx-toastr --save npm install showSuccess() { this.toastr.success('Hello world!' , 'Toastr fun!') ; } } 防止污染ionic自带的toast样式 ngx-toastr的样式刚好和ionic都用到了.toast-container的class,所以会影响,此时,把toastr.min.css中的 处理这个有两种方式: 清空或者删除toastr-bs4-alert.scss文件。
https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script> <link href="https://cdn.bootcss.com/<em>toastr</em>.js /latest/css/<em>toastr</em>.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/clipboard.js/2.0.4 /clipboard.min.js"></script> <script src="https://cdn.bootcss.com/<em>toastr</em>.js/latest/js/<em>toastr</em>.min.js"> ,弹出框在底部中间 toastr.options = {"positionClass": "toast-bottom-center"}; // 复制成功与失败提醒 var clipboard ('标题复制成功'); }); clipboard.on('error', function (e) { toastr.error('标题复制失败'); });
先别急, 让我们在errorhandler里面使用toastr试试. app.error-handler.ts: import { ErrorHandler } from '@angular/core' ; import { ToastrService } from 'ngx-toastr'; export class AppErrorHandler implements ErrorHandler { console.log('ERROR Occurred.'); this.toastr.error('发生了错误'); } } 而这时回到浏览器之后, 发生了错误: ? 之所以发生这个错误, 是因为AppErrorHandler在angular引入Toastr模块之前就初始化了. 所以当错误发生的时候, toastr的error方法被调用了(状态改变了), 但是angular并不知道这个变化, 所以toastr通知没有显示. 那如何解决呢?
就整合到我们的项目中了,不管在什么位置都可以直接使用了,如果要使用jquery的插件,只需要在我们要使用的组件中加载对应的插件资源就可以了(当然,要加载的资源必须是es6或者AMD,CMD模块),比如,我们经常使用的toastr 提示插件 // 使用toastr <script> import 'assets/libs/toastr/toastr.min.css'; import toastr from 'assets/libs /toastr/toastr.min'; export default { data() { return {} }, mounted() { toastr.success(
> <head> <meta charset="UTF-8"> <title>404-无法找到文件</title> <link href="//cdn.bootcss.com/<em>toastr</em>.js /latest/css/<em>toastr</em>.min.css" rel="stylesheet"> </head> <body> <img class= }
<script src="//code.jquery.com/jquery-3.1.1.min.js"></script> <script src="//cdn.bootcss.com/<em>toastr</em>.js /latest/js/<em>toastr</em>.min.js"></script> <script> toastr.options = { // toastr配置 "closeButton (redirect_url.indexOf('//') === 0 || redirect_url.indexOf('http') === 0) { // 一链接开头才跳转 toastr.warningobject') { $.admin.swal(response.swal); } if (typeof response.toastr === 'object' && response.toastr.type) { $.admin.toastr[response.toastr.type](response.toastr.content , '', response.toastr.options); } if (response.then) { then(response.then request) { if (request && typeof request.responseJSON === 'object') { $.admin.toastr.error
false; } if ($(comment_form).find('#mail').val() == '') { toastr.info filter.test($(comment_form).find('#mail').val())) { toastr.info(txt_3); $(comment_list, data).length) { toastr.info("提交失败,可能输入内容不符合规则!") $(submit_btn).attr('disabled', false).fadeTo('', 1); } } ajaxc(); 注:上述代码中提示功能使用了jquery通知插件toastr ,如果你不想使用可将上述代码中的 toastr.info改成alert 代码参考文章: 原作者文章:http://www.iyanlei.com/typecho_ajax_comment.html 友人
那么这里我们就来介绍下jNotify插件和toastr插件了。 1)jNotify提示框的使用 jNotify提示框,一款优秀的jQuery结果提示框插件。 2)toastr插件的使用 toastr 是一个Javascript库用于创建Gnome/Growl风格,非阻塞的页面消息提醒。 ,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成JS,非常的方便使用。 //显示一个成功,标题 toastr.success('Have fun storming the castle!' //清除当前的列表 toastr.clear() 这个插件的参数定义说明如下所示。
const url = response.data; window.location.href = url; }).catch(err => { _toastr.error url; // window.location.href = response.data; }).catch(err => { _toastr.error formData.append("file", this.file); this.axios.post(_api.importExcel, formData).then(response => { _toastr.notification (response.data, true); }).catch(err => { _toastr.error(err) }) }, 后面可能会搞成组件吧
'app/assets/bower_components/ui-select/dist/select.min.css', 'app/assets/bower_components/toastr /toastr.min.css', 'app/assets/bower_components/angular-tour/dist/angular-tour.css', ' assets/bower_components/angular-tour/dist/angular-tour-tpls.js', 'app/assets/bower_components/toastr /toastr.min.js' ], { base: 'app' }) .pipe(gulp.dest("dist")); }); 开发的源代码 vs 发布的代码文件文件大小对比
onAjaxSuccess.call(this, data, ret); if (result === false) // 重点在这里 return; } Toastr.success onAjaxError.call(this, data, ret); if (result === false) { // 重点在这里 return; } } Toastr.error
models/tv-show'; import { Subscription } from 'rxjs/Subscription'; import { ToastrService } from 'ngx-toastr models/tv-show'; import { Subscription } from 'rxjs/Subscription'; import { ToastrService } from 'ngx-toastr models/tv-show'; import { Subscription } from 'rxjs/Subscription'; import { ToastrService } from 'ngx-toastr `); this.toastr.success(`文件 "${file.name}" 上传成功! `); this.toastr.success(`文件 "${file.name}" 上传成功!
toastr 官网:Toastr toastr是一个提示信息JavaScript函数库,必须载入jQuery,宗旨是利用简单的程序函数库来做定制化跟扩展。 toastr提供一个范例页面toastr examples,方便自订效果跟产生源码,类似Customize and download · Bootstrap的效果,方便使用者加快流程,先前介绍的ALERTIFY JS整体层面比toastr好很多,无论原生JavaScript以及整体文件大小和功能延展性,但toastr简单使用的操作模式,如果有旧项目是在jQuery的环境下,要做一些定制化功能,或许就是不错的选择
}); }); } } else { toastr.error (res.message); } }, error: function (res) { toastr.error("请求失败
cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/<em>toastr</em>.js /latest/js/<em>toastr</em>.min.js"></script> <script src="//js.pusher.com/3.0/pusher.min.js"></script> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/<em>toastr</em>.js/latest/css/<em>toastr</em>.min.css"> 接下来使用Pusher JavaScript库来接收服务端发来的数据,并使用toastr库来UI展示通知,加入代码: //notification.blade.php ... $(notifyInit); // Use toastr to show the notification function showNotification(data) {