改造系统alert
/*************************************************************************
* 改造系统alert
* param str 传入要弹出的str
* pos 弹出的位置 1
* 2
* 3
* return false
*************************************************************************/
window.alert = function (str, pos) {
if (document.getElementById("tAlert") || !str) {
return false;
}
var position = '';
var pos = pos || 1;
var tAlert_wrap = document.createElement("div");
tAlert_wrap.setAttribute("id", "tAlert");
tAlert_wrap.style.textAlign = "center";
tAlert_wrap.style.position = "fixed";
tAlert_wrap.style.zIndex = "100";
switch (pos) {
case 1:
position = '10%';
break;
case 2:
position = '40%';
break;
case 3:
position = "65%";
break;
default:
position = "10%";
break;
}
tAlert_wrap.style.top = position;
tAlert_wrap.style.width = "100%";
document.getElementsByTagName("body")[0].appendChild(tAlert_wrap);
var tAlert_in = document.createElement("div");
tAlert_in.style.padding = "0.125rem 0.4375rem";
tAlert_in.style.maxWidth = "6.25rem";
tAlert_in.style.zIndex = "99";
tAlert_in.style.fontSize = "0.375rem";
tAlert_in.style.textShadow = "none";
tAlert_in.style.display = "inline-block";
tAlert_in.style.lineHeight = "0.5rem";
tAlert_in.style.backgroundColor = "#000000";
tAlert_in.style.color = "#ffffff";
tAlert_in.style.borderRadius = "0.1875rem";
tAlert_in.style.opacity = "0.8";
tAlert_in.style.wordBreak = "break-all";
tAlert_in.textContent = str;
document.getElementById("tAlert").appendChild(tAlert_in);
setTimeout(function () {
document.getElementsByTagName("body")[0].removeChild(tAlert_wrap);
}, 2000);
return false;
}
牛了个逼,改造后,弹出会更美丽。弹出会自动关闭。弹出的位置可以自动调整。