Javascript的setTimeout()應用,時間倒數10秒去另一網頁
小舖的問題,小弟寫一個範例,分享給大家呀..javascript
setTimeout.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="setTimeout.aspx.cs" Inherits="setTimeout" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>setTimeout</title>
</head>
<body>
<form id="form1" runat="server">
<div id='div1'>
</div>
</form>
</body>
</html>
<script type="text/javascript">
//設定倒數秒數
var t = 10;
//顯示倒數秒收
function showTime()
{
t -= 1;
document.getElementById('div1').innerHTML= t;
if(t==0)
{
location.href='http://www.dotblogs.com.tw/puma/';
}
//每秒執行一次,showTime()
setTimeout("showTime()",1000);
}
//執行showTime()
showTime();
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>setTimeout</title>
</head>
<body>
<form id="form1" runat="server">
<div id='div1'>
</div>
</form>
</body>
</html>
<script type="text/javascript">
//設定倒數秒數
var t = 10;
//顯示倒數秒收
function showTime()
{
t -= 1;
document.getElementById('div1').innerHTML= t;
if(t==0)
{
location.href='http://www.dotblogs.com.tw/puma/';
}
//每秒執行一次,showTime()
setTimeout("showTime()",1000);
}
//執行showTime()
showTime();
</script>
參考網址:
http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
http://www.blueshop.com.tw/board/show.asp?subcde=BRD200804290031209IQ&fumcde=FUM20041006161839LRJ&rplcnt=0