jQuery 弹出窗口2秒后自动关闭

修改数据后需要给用户一个提示,下面是html代码:

<!DOCTYPE HTML>
<html>
<head>
    <title>可设置内容弹出层,2秒自动消失</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="js/saveTip.js" type="text/javascript"></script>
<style type="text/css">
.alertWindowContent h1,p{text-align: center;font-size: 18px;font-weight: bolder;}
.alertWindowContent input{width: 100px; height: 50px;cursor: pointer;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}
</style>
<script>
    $(function(){
        $("#input1").click(function(){
            jQuery.alertWindow("保存成功");
        });
        $("#input2").click(function(){
            jQuery.alertWindow("修改成功");
        });
    });
</script>
</head>
<body>
 <!-- 代码 开始 -->
<center><br><br><br><br><br><br><br><br>
<input type="button" value="按钮1" id="input1">
<input type="button" value="按钮2" id="input2">
</center>
</body>
</html>
jQuery代码如下:

jQuery.extend({
    	alertWindow:function(e,n){var e=e,r;n===undefined?r="#00a8b7":r=n;
    	if($("body").find(".alertWindow1").length===0){
    		var i='<div class="alertWindow1" style="width: 100%;height: 100%; background:rgba(0,0,0,0.5);position: fixed; left:0px; top: 0px; z-index: 9999;"><div  style="width: 360px; height: 170px;background: #FFF;margin: 300px auto;border: 2px solid #CFCFCF;">'+'<div  style="width: inherit;height: 20px;">'+'<div class="alertWindowCloseButton1" style="float: right; width: 10px; height: 30px;margin-right:5px;font-family:\'microsoft yahei\';color:'+r+';cursor: pointer;"></div>'+"</div>"+'<div id="successImg" class="alertWindowTitle" style="margin-top:10px;text-align:center;font-family:\'Verdana, Geneva, Arial, Helvetica, sans-serif\';font-size: 18px;font-weight: normal;color: '+r+';">'+"</div>"+'<div class="alertWindowContent" style="width:360px;height: 40px;text-align:center;font-size: 18px;color: #7F7F7F;margin-top:10px;">'+e+"</div>"+"</div>"+"</div>";
    		$("body").append(i);
    		var s=$(".alertWindow1");
    		//2秒后自动关闭窗口
    		setTimeout(function(){s.hide()},1000);
    	}
    	else {$(".alertWindowContent").text(e),$(".alertWindow1").show(),setTimeout(function(){$(".alertWindow1").hide()},1000);}
    	}
    	}) 
引入了一张图片,css样式如下:

#successImg{
	width: 58px;
	height: 58px;
	margin: 0px auto;
	background: url("../img/successIcon.png") no-repeat ;
	border:none;
}
整体效果如下图:




  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值