微信重写confirm方法

微信重写confirm方法

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>JavaScript中alert()方法重写</title>
		<script src="js/jquery-2.1.0.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<style type="text/css">
			*{margin:0;padding:0;font-size:12px;}
			.confirm_ul{list-style:none;margin:0px;padding:0px;width:70%;margin: auto;margin-top: 40%;}
			.confirm_title{background:#F2F2F2;text-align:left;padding-left:20px;line-height:60px;border:1px solid #999;}
			.confirm_content{background:#fff;text-align:center;height:80px;line-height:80px;}
			.confirm_btn-wrap{background:#fff;height:30px;line-height:18px;text-align: right;}
			.confirm_btn{cursor:pointer;color:#2bd00f;margin-right: 35px;}
			.confirm_btn-wrap > a:nth-child(1){color: #9c9898;}
		</style>
		<script type="text/javascript">
			var a=function(){
				alert("ok");
			};
		function Confirm(str,click)
		{
		    
		    var confirmFram = document.createElement("DIV");
		    confirmFram.id="confirmFram";
		    confirmFram.style.position = "absolute";
		    confirmFram.style.width = "100%";
		    confirmFram.style.height = "100%";
		    confirmFram.style.top = "0";
		    confirmFram.style.textAlign = "center";
		    confirmFram.style.lineHeight = "150px";
		    confirmFram.style.zIndex = "300";
		    confirmFram.style.backgroundColor="rgba(0, 0, 0, 0.58)";
		    confirmFram.style.fontSize="12px";
		    strHtml = '<ul class="confirm_ul">';
		    strHtml += '<li class="confirm_content">'+str+'</li>';
		    strHtml += '<li class="confirm_btn-wrap"><a type="button" value="确定" οnclick="doFalse()" class="confirm_btn">取消</a><a type="button" value="确定" οnclick="doOk()" class="confirm_btn">确定</a></li>';
		    strHtml += '</ul>';
		    confirmFram.innerHTML = strHtml;
		    document.body.appendChild(confirmFram);
		    this.doOk = function(){
		        confirmFram.style.display = "none";
		        if(typeof click=="function"){
		        	click();
		        	return true;
		        }
		        	
		    }
		    this.doFalse = function(){
		        confirmFram.style.display = "none";
		        if(typeof click=="function"){
		        	return false;
		        }
		        	
		    }
		}
		
		console.log(Confirm('这是自定义的confirm',a));
		/*if(confirm('这是自定义的ALERT')){
			console.log('true');
		}else{
			console.log('false');
		}*/
		</script>
		<p style="position: absolute;bottom: 0px;z-index: 1;">
		mlksdfsjkdfn
		</p>
	</body>
</html>

效果如下图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值