js:
function alertError(msg,code){
alertErrorF(msg,code,null, 2000);
}
function alertErrorF(msg,code,f, ms){
if(ms==undefined) ms=2000;
$(".alertError").remove();
$("body").append("<div class='alertError' style='display: block;position:absolute;zoom:1;z-index:2147483647;'>"+msg+"</div>");
if(code>0){
$(".alertError").addClass("alertSucc");
}else{
$(".alertError").removeClass("alertSucc");
}
window.setTimeout(function(){
$(".alertError").remove();
if(f!=null && typeof(f) == "function" && code>0){
f.call(f);
}
},ms)
}
css:
.alertError{
display:none;
min-width:100px;
max-width:200px;
width:auto;
position:fixed;
left:50%;
top:40%;
margin-left:-80px;
word-wrap:break-word;
border:none;
padding:10px 20px;
background-color:#ff5660;
border-radius:5px;
-moz-border-radius:5px;
box-shadow:0 5px 27px rgba(0,0,0,0.3);
-webkit-box-shadow:0 5px 27px rgba(0,0,0,0.3);
-moz-box-shadow:0 5px 27px rgba(0,0,0,0.3);
_display:block;
z-index:101;
padding:20px;
color: white;
text-align:center;
}
jsp:
<div class="alertError" ></div> 使用: alertError("添加成功","1");
转载于:https://blog.51cto.com/wyshnc/1910632