重写confirm返回值的问题
<styletype="text/css">.popup{width:350px;position:absolute;top:40%;left:40%;backgroun...
<style type="text/css">
.popup {width: 350px;position: absolute;top:40%;left: 40%;background: #FFFFFF;z-index: 2000;text-align: center;font-size: 14px;}
.popup .pop_btn{padding-bottom: 10px;}
.f_title{width: 100%;background: #3D6FAC;color: #FFFFFF;height: 30px;line-height: 30px;text-align: left;margin-bottom: 20px;}
.f_title i{padding-left: 10px;font-style: normal;font-size: 14px;font-weight: bold;}
.f_error {color: red;margin-left: 5px;display: none;}
.covered{display:none;float:left;opacity:0.4; filter:alpha(opacity=60);width: 100%;height: 150%;position: absolute;background: black;z-index: 1000;left:0;top: 0;}
.none{display: none;}
</style>
<div class='popup none' id='ConfirmMessageForm'>
<div class="f_title" id="_c_title"><i>消息</i></div>
<div class="f_message" id="_c_message" style="margin:20px;"></div>
<div class="pop_btn"><input type="button" value="确定" id="_c_true">
<input type="button" value="取消" class="pop_close" id="_c_false"></div>
</div>
<div class='covered' id="_covered"></div>
<script type="text/javascript">
window.confirm = function(message, okCallBack, cancelCallBack){
var myConfirm = document.getElementById('ConfirmMessageForm'),
myCovered = document.getElementById("_covered");
document.getElementById("_c_message").innerHTML = message;
myConfirm.style.display = "block";
myCovered.style.display = "block";
}
var a = confirm("1111111111111");
console.log(a);
</script>
重写js中confirm函数,关于点击确定返回true,取消返回false一直实现不了。求解决方案 展开
.popup {width: 350px;position: absolute;top:40%;left: 40%;background: #FFFFFF;z-index: 2000;text-align: center;font-size: 14px;}
.popup .pop_btn{padding-bottom: 10px;}
.f_title{width: 100%;background: #3D6FAC;color: #FFFFFF;height: 30px;line-height: 30px;text-align: left;margin-bottom: 20px;}
.f_title i{padding-left: 10px;font-style: normal;font-size: 14px;font-weight: bold;}
.f_error {color: red;margin-left: 5px;display: none;}
.covered{display:none;float:left;opacity:0.4; filter:alpha(opacity=60);width: 100%;height: 150%;position: absolute;background: black;z-index: 1000;left:0;top: 0;}
.none{display: none;}
</style>
<div class='popup none' id='ConfirmMessageForm'>
<div class="f_title" id="_c_title"><i>消息</i></div>
<div class="f_message" id="_c_message" style="margin:20px;"></div>
<div class="pop_btn"><input type="button" value="确定" id="_c_true">
<input type="button" value="取消" class="pop_close" id="_c_false"></div>
</div>
<div class='covered' id="_covered"></div>
<script type="text/javascript">
window.confirm = function(message, okCallBack, cancelCallBack){
var myConfirm = document.getElementById('ConfirmMessageForm'),
myCovered = document.getElementById("_covered");
document.getElementById("_c_message").innerHTML = message;
myConfirm.style.display = "block";
myCovered.style.display = "block";
}
var a = confirm("1111111111111");
console.log(a);
</script>
重写js中confirm函数,关于点击确定返回true,取消返回false一直实现不了。求解决方案 展开
1个回答
展开全部
原生的confirm是通过线程阻塞达到这种目的,而在js里面无法达到这种效果,请弄清楚“同步”“异步”的概念。因此你这个思路是走不通的,函数调用完毕之时,你自定义的弹出框仅仅刚显示出来。但是你采用回掉的思路是正确的。
myCovered.style.display = "block";之后追加以下代码
document.getElementById("_c_true").onclick = okCallBack;
document.getElementById("_c_false").onclick = cancelCallBack;
就可以实现确认和取消的回调。
myCovered.style.display = "block";之后追加以下代码
document.getElementById("_c_true").onclick = okCallBack;
document.getElementById("_c_false").onclick = cancelCallBack;
就可以实现确认和取消的回调。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询