$(document).ready(function(){
//提示成功信息
ShowSuccessMessage = function(message, life) {
var time = 50000;
if (!life) {
time = life;
}
if ($("#tip_message").text().length > 0) {
var msg = "<span>" + message + "</span>";
$("#tip_message").empty().append(msg);
} else {
var msg = "<div id="tip_message"><span>" + message + "</span></div>";
$("body").append(msg);
}
$("#tip_message").fadeIn(time);
setTimeout($("#tip_message").fadeOut(time), time);
};
//提示错误信息
ShowErrorMessage = function(message, life) {
ShowSuccessMessage(message, life);
$("#tip_message span").addClass("error");
};
ShowMessage("Hello success!", 5000); // 第二个参数life是指消息显示时间
ShowErrorMessage("Hello error!", 50000);
});
------------------------------------------------------------------
#tip_message {
z-index: 9999;
position: fixed;
left: 0;
top: 40%;
text-align: center;
width: 100%;
}
#tip_message span {
background-color: #03C440;
opacity: .8;
padding: 20px 50px;
border-radius: 5px;
text-align: center;
color: #fff;
font-size: 20px;
}
#tip_message span.error {
background-color: #EAA000;
}