我的代碼哪出問題呢了
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title>?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
<h1><strong>操作成功</strong></h1>
<span id="block">5</span><span>秒后回到首頁</span><a href="window.history.back()">返回</a>
?
?
? <script type="text/javascript">?
? function second(){
? document.getElementById("block").innerHTML=var num;
?? num=5;
?? num--;
???? if(num==0){
???????? location.href("idcbgp.cn");
????? }
? }
? setInterval("second()",1000);
為什么秒不變呢
2016-03-15
問題有好幾處呢:1,先定義var num=5;然后再輸出document.getElementById("block").innerHTML=num;輸出后進行自減,num--;2,打開網(wǎng)頁應(yīng)該是location.assign("http://idcbgp.cn");location.href("http://idcbgp.cn")是返回()里的字符串也就是網(wǎng)址。