1 html meta 字段實(shí)現(xiàn)
這種是最簡(jiǎn)單的。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 相對(duì)路徑 -->
<meta http-equiv="Refresh" content="3,url=IndexServlet">
<title>跳轉(zhuǎn)...</title>
</head>
<body>
</body>
</html>
content="3,url=IndexServlet" 中3是指延遲3秒。
2 js setTimout
通過(guò)setTimeout執(zhí)行一個(gè)延遲函數(shù)來(lái)達(dá)到跳轉(zhuǎn)的目的。
setTimeout(jump,3000);
function jump(){
window.location.href='IndexServlet';
}
3 js setInterval 實(shí)現(xiàn)頁(yè)面顯示倒計(jì)時(shí)
通過(guò)setInterval函數(shù),來(lái)周期性的更新倒計(jì)時(shí)間,同時(shí)更新到頁(yè)面。頁(yè)面上的顯示效果是3 2 1,然后跳轉(zhuǎn)到index.html
<span id="remainSeconds">3</span>
<script type="text/javascript">
setInterval(jump,1000);
var sec = 3;
function jump(){
sec--;
if(sec > 0){
document.getElementById('remainSeconds').innerHTML = sec;
}else{
window.location.href = 'index.html';
}
}
</script>
4 js setTimeout 實(shí)現(xiàn)頁(yè)面顯示倒計(jì)時(shí)
通過(guò)setTimeout 函數(shù),來(lái)周期性的更新倒計(jì)時(shí)間,同時(shí)更新到頁(yè)面。頁(yè)面上的顯示效果是3 2 1,然后跳轉(zhuǎn)到index.html
<span id="remainSeconds">3</span>
<script type="text/javascript">
var sec = 3;
function jump(){
sec--;
if(sec > 0){
document.getElementById('remainSeconds').innerHTML = sec;
setTimeout(this.jump,1000);
}else{
window.location.href = 'index.html';
}
}
setTimeout(jump,1000);
</script>