給大家推薦一款jquery提示插件:toastr
它是一個可以取代alert的提示信息框,它在PC,移動設備上都有不錯的UI效果。
具體使用方法如下:
1、首先在網頁頭站調用他需要的js和css文件。
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script src="https://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script> <link href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
2、然后就可以自定義該組件的相關參數和事件了。
比如彈出的位置,大小,配色,類型等等。
<script type="text/javascript">
//美化版彈窗
$(function(){
var messageOpts = {
"closeButton": false,
"debug": false,
"positionClass": "toast-top-right",
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
toastr.options = messageOpts;
$('#showtoast').click(function() {
//提示
//調用方法1
toastr.info('內容1');
//調用方法2
//toastr.info('內容2', '標題2');
//調用方法3
//toastr['info']('內容3', '標題3');
//調用方法4
//toastr.info('內容4', '標題4',messageOpts);
});
$('#showtoastsuccess').click(function() {
//成功
toastr.success('內容success', '標題success');
});
$('#showtoasterror').click(function() {
//錯誤
toastr.error('內容error', '標題error');
});
$('#showtoastwarning').click(function() {
//警告
toastr.warning('內容warning', '標題warning');
});
})
</script>
3、HTML中調用相關事件:
<button id="showtoast">show info toast(提示)</button> <br> <button id="showtoastsuccess">show success toast(成功)</button> <br> <button id="showtoasterror">show error toast(錯誤)</button> <br> <button id="showtoastwarning">show warning toast(警告)</button>
該插件完整演示頁:
http://www.shouce.ren/api/jq/5733e3732c588/index.html
懶人黨福利,完整代碼直接測試:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>
<link href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
<script type="text/javascript">
//美化版彈窗
$(function(){
var messageOpts = {
"closeButton": false,
"debug": false,
"positionClass": "toast-top-right",
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
toastr.options = messageOpts;
$('#showtoast').click(function() {
//提示
//調用方法1
toastr.info('內容1');
//調用方法2
//toastr.info('內容2', '標題2');
//調用方法3
//toastr['info']('內容3', '標題3');
//調用方法4
//toastr.info('內容4', '標題4',messageOpts);
});
$('#showtoastsuccess').click(function() {
//成功
toastr.success('內容success', '標題success');
});
$('#showtoasterror').click(function() {
//錯誤
toastr.error('內容error', '標題error');
});
$('#showtoastwarning').click(function() {
//警告
toastr.warning('內容warning', '標題warning');
});
})
</script>
</head>
<body>
<button id="showtoast">show info toast(提示)</button>
<br>
<button id="showtoastsuccess">show success toast(成功)</button>
<br>
<button id="showtoasterror">show error toast(錯誤)</button>
<br>
<button id="showtoastwarning">show warning toast(警告)</button>
</body>
</html>
