<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>重写alert</title>
<style>
div, p {
margin: 0;
padding: 0;
}
div {
background-color: #00bbee;
width: 100px;
height: 100px;
border-radius: 100px;
position: absolute;
left: 50%;
top: 10%;
margin-left: -50px;
}
p {
width: 200px;
color: #00bbee;
position: relative;
bottom: -120px;
right: 50%;
margin-left: 25px;
font-size: 20px;
}
</style>
<script>
window.alert = function (txt, time) {
if (document.getElementById("alertFram")) {
return;
}
var alertDiv = document.createElement("DIV");
alertDiv.id = "alertFram";
alertDiv.style.position = "absolute";
alertDiv.style.left = "50%";
alertDiv.style.top = "40%";
alertDiv.style.marginLeft = "-225px";
alertDiv.style.marginTop = "-75px";
alertDiv.style.width = "450px";
alertDiv.style.height = "150px";
alertDiv.style.background = "#ccc";
alertDiv.style.textAlign = "center";
alertDiv.style.lineHeight = "150px";
alertDiv.style.zIndex = "10000";
alertDiv.innerHTML = "<ul style='list-style:none;margin:0px;padding:0px;width:100%'><li style='background:#DD828D;text-align:left;padding-left:10px;font-size:14px;font-weight:bold;height:27px;line-height:25px;border:1px solid #F9CADE;'>温馨提示</li><li style='background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;'>" + txt + "</li><li style='background:#FDEEF4;text-align:center;font-weight:bold;height:27px;line-height:25px; border:1px solid #F9CADE;'οnclick='doOk()'><input type='button' style='background-color: #FDEEF4;border: none;outline:none;' value='确 定'/></li></ul>";
document.body.appendChild(alertDiv);
var c = 0;
this.timer = function () {
if (c++ >= time) {
clearInterval(ad);
document.body.removeChild(alertDiv);
}
}
var ad = setInterval("timer()", 1000);
this.doOk = function () {
document.body.removeChild(alertDiv);
}
alertDiv.focus();
document.body.onselectstart = function () {
return false;
};
}
</script>
</head>
<body>
<div οnclick="alert('大家好啊!!!')">
<p>please click it !!!</p>
</div>
</body>
</html>
js弹窗之重写alert
原创day_day_up_cium ©著作权
©著作权归作者所有:来自51CTO博客作者day_day_up_cium的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
js中的弹窗alert、confirm和prompt
ndow 对象位于对象层次的顶层,因此实际应用中不必使用这些消息框的全名(例如 "window.alert
js弹窗 JavaScript alert confirm prompt -
alert弹窗方法1
1.代码 结果显示:
html 获取标签