為什么不倒計(jì)時(shí)啊
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對(duì)象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
? ?<style>
? ?#txt1{
? ? color:black;
font-size:20px;
font-weight:bold;
? ?}
? ?#txt2{
? ?font-size:18px;
? ?}
? ?</style> ?
?</head>
?<body>
? ?<div>
? ? ?<span id="txt1">操作成功<br/><br/></span>
? ? <span id="txt2"><span id="count">5</span>秒后回到主頁<a href="javascript:window.history.back()" id="back">返回</a></span>
? ?</div>
??
?
? <script type="text/javascript"> ?
? ?;
? function startCount(){
? ? var num=5;
var i;
? ? document.getElementById("count").innerHTML=num;
? ? num=num-1;
? ? if(num==0){
? ? ?clearTimeout(i);
? ? ?window.location.assign("idcbgp.cn");
? }
else{
? ? ? ? i=setTimeout("startCount()",1000);
}
? }
?</script>?
</body>
</html>
2018-11-13
你得調(diào)用啊,不掉用怎么行
2018-11-13
計(jì)時(shí)函數(shù)沒用被調(diào)用。
兩種修改方法:
1、給body標(biāo)簽添加屬性:
<body onload="startCount()">
2、使用setInterval方法。
2018-11-07
var num=5;
var i=setInterval("fun()",2000);
function fun(){
if(i==0){
window.location.href=("idcbgp.cn")
clearInterval(i);
}
document.getElementById("count").innerHTML=i;
i--;
}