詳細內容請下載附件 附件下載
先看一下效果:
內容都集合到一個1.58KB的js文件裡
代碼如下:
var returnurl = '';
var messagebox_timer;
$.fn.messagebox = function (message, url, type, delay) {
clearTimeout(messagebox_timer);
$("#msgprint").remove();
var m_body = $(this);
delay = (typeof delay == "undefined" ? 5000 : delay);
returnurl = url;
var box_style = 'position:absolute;display:none;z-index:1000;padding:10px 30px 10px 40px;';
switch (type) {
case 1: box_style += 'border:1px solid Green;color:#090;background:url(../Icons/ok.png) 10px 10px no-repeat #F1FEF2;'; break;
case 0: box_style += 'border:1px solid Red;color:#EE1010;background:url(../Icons/error.png) 10px 10px no-repeat #FDF8E8;'; break;
default: box_style += 'border:1px solid Orange;color:Orange;background:url(../Icons/warning.png) 10px 10px no-repeat #FEFDE9;'; break
}
var str = "<div id=\"msgprint\" style=\"" + box_style + "\">" + message + "</div>"; m_body.append(str);
var dom_obj = document.getElementById("msgprint");
var ext_width = $("#msgprint").width();
dom_obj.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - dom_obj.offsetHeight - $("#msgprint").height()) / 2) + "px";
dom_obj.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - dom_obj.offsetWidth - $("#msgprint").width()) / 2) + "px";
$("#msgprint").fadeIn(1000, function () { messagebox_timer = setTimeout(messagebox_out, delay) });
};
function messagebox_out() {
if (returnurl == undefined || returnurl == '') { $("#msgprint").fadeOut(1000) }
if (returnurl == "back") { this.history.back(-1) } else if (returnurl != "" && returnurl != undefined) { this.location.href = returnurl }
}
引用的js文件:
代碼如下:
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="Scripts/Jquery.L.Message.js" type="text/javascript"></script>
頁面代碼:
代碼如下:
<body>
<div id="hello" style="height: 350px;">
<ul><li><a href="javascript:$('#hello').messagebox('成功提示<br/>成功提示', 'http://localhost:5083/', 1, 20000);">成功,20秒後跳轉</a></li>
<li> <a href="javascript:$('#hello').messagebox('錯誤提示<br/>錯誤提示', '', 0, 1000);">失敗,1秒消失</a></li>
<li> <a href="javascript:$('body').messagebox('這是警告<br/>這是警告', 'back', 2);">警告,默認時間5秒後後退</a></li></ul></div></body>