<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#toast {
color:rgb(11,90,22);
position:absolute;
bottom:50%;
left:50%;
display:none;
}
</style>
</head>
<body>
<input type="button" id="toast" value="">
<input type="button" value="正常" onclick="correct()">
<input type="button" value="异常报错" onclick="error()">
<script type="text/javascript">
function toast(text,time){
document.getElementById("toast").value=text;
document.getElementById("toast").style.display="inline-block";
setTimeout(function(){
document.getElementById("toast").style.display="none";
},time);
}
function correct(){
toast("成功啦",1000);
}
function error(){
toast("异常报错喽",1000);
}
</script>
</body>
</html>
JS使用定时器+display属性实现弹窗效果
最新推荐文章于 2023-07-06 12:59:53 发布