微信重写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>
效果如下图: