[英]javascript confirm() terminate my script when dialog opened
i have script for showing seconds of the hour, demo jsfiddle here 我有显示小时的脚本,演示jsfiddle 在这里
following my script : 按照我的脚本:
<script type="text/javascript">
function updateClock() {
var now = new Date();
var seconds = now.getSeconds();
var elem = document.getElementById('clock');
elem.innerHTML = seconds;
}
function confirma(){
confirm('confirmation?');
}
</script>
<body onload="setInterval('updateClock()', 200);">
<h1 id="clock"></h1>
<button onclick="confirma()">confirm!</button>
</body>
my script works well, but when i click button "confirm!", the seconds not increase (freeze), why? 我的脚本运行良好,但是当我单击“确认!”按钮时,秒数没有增加(冻结),为什么?
You can pure Html instead of pop-up, becouse pop-ups will stop javascript until you click yes or no. 您可以使用纯HTML格式来代替弹出式窗口,因为弹出式窗口将停止javascript,直到您单击“是”或“否”。
My suggestion is to you this put this html after your confirm button 我的建议是向您发送此HTML,然后单击确认按钮
<div id="test" class="testOld">
Do you want to confirm
<button onclick="test()">Yes</button>
<button onclick="test2()">No</button>
</div>
Add this css 添加这个CSS
.testOld{
display:none;
}
.testNew{
display:block;
}
And modify your javacript like this : 并像这样修改您的javacript:
function confirma(){
$("#test").removeClass("testOld");
$("#test").addClass("testNew");
}
function test(){
// code after yes
}
function test2(){
//code after no
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.