本身不熟悉js略懂JQuery,闲着没事帮朋友公司一个程序小伙修改了个消息提示框,把修改后的代码和代价分享一下,详细内容请下载附件 附件下载
先看一下效果:
内容都集合到一个1.58KB的js文件里
1 var returnurl = '';
2 var messagebox_timer;
3 $.fn.messagebox = function (message, url, type, delay) {
4 clearTimeout(messagebox_timer);
5 $("#msgprint").remove();
6 var m_body = $(this);
7 delay = (typeof delay == "undefined" ? 5000 : delay);
8 returnurl = url;
9 var box_style = 'position:absolute;display:none;z-index:1000;padding:10px 30px 10px 40px;';
10 switch (type) {
11 case 1: box_style += 'border:1px solid Green;color:#090;background:url(../Icons/ok.png) 10px 10px no-repeat #F1FEF2;'; break;
12 case 0: box_style += 'border:1px solid Red;color:#EE1010;background:url(../Icons/error.png) 10px 10px no-repeat #FDF8E8;'; break;
13 default: box_style += 'border:1px solid Orange;color:Orange;background:url(../Icons/warning.png) 10px 10px no-repeat #FEFDE9;'; break
14 }
15 var str = "
16 var dom_obj = document.getElementById("msgprint");
17 var ext_width = $("#msgprint").width();
18 dom_obj.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - dom_obj.offsetHeight - $("#msgprint").height()) / 2) + "px";
19 dom_obj.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - dom_obj.offsetWidth - $("#msgprint").width()) / 2) + "px";
20 $("#msgprint").fadeIn(1000, function () { messagebox_timer = setTimeout(messagebox_out, delay) });
21 };
22 function messagebox_out() {
23 if (returnurl == undefined || returnurl == '') { $("#msgprint").fadeOut(1000) }
24 if (returnurl == "back") { this.history.back(-1) } else if (returnurl != "" && returnurl != undefined) { this.location.href = returnurl }
25 }
引用的js文件:
<script src&#61;"http://code.jquery.com/jquery-latest.js" type&#61;"text/Javascript"></script>
<script src&#61;"Scripts/Jquery.L.Message.js" type&#61;"text/Javascript"></script>
页面代码&#xff1a;
<body>
<div id&#61;"hello" style&#61;"height: 350px;">
<ul><li><a href&#61;"Javascript:$(&#39;#hello&#39;).messagebox(&#39;成功提示
成功提示&#39;, &#39;http://localhost:5083/&#39;, 1, 20000);">成功&#xff0c;20秒后跳转a>li>
<li> <a href&#61;"Javascript:$(&#39;#hello&#39;).messagebox(&#39;错误提示
错误提示&#39;, &#39;&#39;, 0, 1000);">失败&#xff0c;1秒消失a>li>
<li> <a href&#61;"Javascript:$(&#39;body&#39;).messagebox(&#39;这是警告
这是警告&#39;, &#39;back&#39;, 2);">警告&#xff0c;默认时间5秒后后退a>li>ul>div>
body>