欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript 實(shí)現(xiàn)簡單的倒計時彈窗DEMO附圖

 更新時間:2014年03月05日 16:47:56   作者:  
做一個簡單的設(shè)置網(wǎng)頁,因為需要重啟設(shè)備功能,于是就想在上面加一個倒計時彈窗的界面,下面是具體的實(shí)現(xiàn),大家可以參考下
最近做一個簡單的設(shè)置網(wǎng)頁,因為需要重啟設(shè)備功能,于是就想在上面加一個倒計時彈窗的界面。

剛開始的想法是自定義一個alert彈窗,但很快就發(fā)現(xiàn),alert會一直停在那里等待點(diǎn)擊確認(rèn),而不是我想要的那種自動連續(xù)顯示的效果。

后來,才想到直接顯示和隱藏DIV制作成的彈窗,就可以實(shí)現(xiàn)了?;谶@個思路,于是有了下面的:

先看效果圖:
 
 
再看源代碼:
復(fù)制代碼 代碼如下:

<!------------------ 重啟操作 準(zhǔn)備彈窗 --------------->
<div id="reboot_pre" style="width: 450px; height: 200px; margin-left:auto; margin-right:auto; margin-top:200px; visibility:hidden; background: #F0F0F0; border:1px solid #00DB00; z-index:9999">
<div style="width: 450px; height: 30px; background:#00DB00; line-height:30px;text-align: center;"><b>準(zhǔn)備中</b></div>
<br /><br />
<div><p style="margin-left:50px">正在努力為您準(zhǔn)備重啟操作... 還需稍候 <span id="reboot_pre_time">4</span> 秒</p></div>
<br />
<div><button type="button" style="width:70px; height:30px; margin-left:340px" onclick="reboot_cancel()">取消</button></div>
</div>
<!------------------ 重啟操作 準(zhǔn)備彈窗 --------------->

<!------------------ 重啟操作 進(jìn)行彈窗 --------------->
<div id="reboot_ing" style="width: 450px; height: 150px; margin-left:auto; margin-right:auto; margin-top:-150px; visibility: hidden; background: #F0F0F0; border:1px solid #00DB00">
<div style="width: 450px; height: 30px; background:#00DB00; line-height:30px;text-align: center;"><b>進(jìn)行中</b></div>
<br />
<div><p style="margin-left:40px">重啟操作正在進(jìn)行中... 還需稍候 <span id="reboot_ing_time">14</span> 秒</p></div>
<br />
<div id="progress_reboot" style="margin-left:40px;color:#00DB00;font-family:Arial;font-weight:bold;height:18px">|</div>
<br />
</div>
<!------------------ 重啟操作 進(jìn)行彈窗 --------------->


lt;script type="text/javascript">

var cancel_flag = 0;
var already = 0;

/* 網(wǎng)頁一加載就執(zhí)行的操作 */
window.onload = reboot();

/* 重啟按鈕的單擊操作 */
function reboot(){
if(confirm("這個操作會斷開現(xiàn)在所有的連接,并且重新啟動您的設(shè)備,確定要繼續(xù)操作嗎?")){
document.getElementById("reboot_pre_time").innerHTML = 4;
document.getElementById("reboot_ing_time").innerHTML = 14;
document.all.progress_reboot.innerHTML = "|";
download_flag = 0;
cancel_flag = 0;
already = 0;
setTimeout("showDiv('reboot_pre')",500);
delayPre_reboot("reboot_pre_time");
}
}
/* 重啟準(zhǔn)備彈窗計時 5秒 */
function delayPre_reboot(str) {
if(!cancel_flag){
var delay = document.getElementById(str).innerHTML;
if(delay > 0) {
delay--;
document.getElementById(str).innerHTML = delay;
setTimeout("delayPre_reboot('reboot_pre_time')", 1000);
} else {
hideDiv("reboot_pre");
setTimeout("showDiv('reboot_ing')",500);
delayDo_reboot("reboot_ing_time");
}
}
}
/* 重啟進(jìn)行中彈窗計時 15秒 */
function delayDo_reboot(str){
display_reboot(100);
var delay = document.getElementById(str).innerHTML;
if(delay > 0) {
delay--;
document.getElementById(str).innerHTML = delay;
setTimeout("delayDo_reboot('reboot_ing_time')", 1000);
} else {
hideDiv("reboot_ing");
alert("重啟成功!");
}
}
/* 重啟準(zhǔn)備時 取消按鈕的事件*/
function reboot_cancel(){
cancel_flag = 1;
hideDiv("reboot_pre");
alert("您已經(jīng)成功取消了重啟操作!");
}
/* 顯示彈窗 */
function showDiv (str){
document.getElementById(str).style.visibility = "visible";
}
/* 隱藏彈窗 */
function hideDiv (str){
document.getElementById(str).style.visibility = "hidden";
}

/* 重啟進(jìn)行中彈窗計時,緩沖條的移動*/
function display_reboot(max){
already++;
var dispObj = document.all.progress_reboot;
dispObj.style.width = 100.0*already/max+"px";
document.all.progress_reboot.innerHTML += "|||||";
var timer = window.setTimeout("display("+max+")",1000);
if (already >= max){
window.clearTimeout(timer);
}
}

</script>

相關(guān)文章

最新評論