為什么我的if判斷語句不會執(zhí)行,不能轉(zhuǎn)跳啊
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <h1>操作成功</h1>
? <p><span Id="t">5</span>秒后回到主頁 ? <a href="Javascript:back()">返回</a></p>?
? <script type="text/javascript"> ??
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
? ?var s=document.getElementById("t").innerHTML
? ?function Count()
? ?{
? ? ? ?s--;
? ? ? ?document.getElementById("t").innerHTML = s;?
? ? ? ?if(s==o)
? ? ? ?{
? ? ? ? ? ?window.location.assign("http://www.baidu.com");
? ? ? ?}
? ?}
? ?setInterval(Count,1000);
? ? ? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ? function bak()
?{
? ?window.history.back();
?}
?</script>?
</body>
</html>
2016-02-24
你的邏輯 沒有錯
應該是s==0,你寫成o了,還有就是你的書寫沒規(guī)范,
像下面這樣就是正確的
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
? <h1>操作成功</h1>
? <p><span Id="t">5</span>秒后回到主頁 ? <a href="Javascript:back()">返回</a></p>?
? <script type="text/javascript"> ??
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
? ?var s=document.getElementById("t").innerHTML
? ?function Count()
? ?{
? ? ? ?s--;
? ? ? ?document.getElementById("t").innerHTML=s;?
? ? ? ?if(s==0)
? ? ? ?{
? ? ? ? ? ?window.location.assign("http://www.baidu.com");
? ? ? ?}
? ?}
? ?setInterval(Count,1000);
? ? ? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ? function bak()
?{
? ?window.history.back();
?}
?</script>?
</body>
</html>