第八章編程練習
? <script type="text/javascript">??
?var sec=document.getElementById("second");
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
var i=5;
? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ? var repeat=setInterval( "daojishi()",1000);
? ?function daojishi()
? ?{
? ? ? ?i--;
? ? ? ?sec.innerHTML=i;
? ? ? ?if(i==1)
? ? ? ?{
? ? ? ? ? ?window.location.;
? ? ? ? ? ?//window.open("http://idcbgp.cn","_blank");
? ? ? ? ? ? clearInterval(repeat);
? ? ? ?}
? ?}
為什么不跳轉(zhuǎn),計時無法清除?
2018-05-21
<!DOCTYPE html>
<html lang="en">
<head>
????<meta charset="UTF-8">
????<meta name="viewport" content="width=device-width, initial-scale=1.0">
????<meta http-equiv="X-UA-Compatible" content="ie=edge">
????<title>Document</title>
</head>
<body>
????<div id="second">5</div>
<script type="text/javascript"> ?
var sec=document.getElementById("second");
//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
var i = 5;
//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
var repeat = setInterval( "daojishi()",1000);
function daojishi(){
???? i--;
???? sec.innerHTML=i;
????if(i==1){
????????window.open('http://www.baidu.com');
????
???? //window.open("http://idcbgp.cn","_blank");
???? clearInterval(repeat);
????}
}
</script>???????????
</body>
</html>
當i=1的時候網(wǎng)頁會跳轉(zhuǎn),在瀏覽器測試可能會被插件阻止,具體瀏覽器設(shè)置可以參考open()設(shè)置
2022-03-23
為什么我加括號后沒變化?不想無窮的加載,只要把后面又加上的三張圖片加載出來就可以啦,怎么辦?刪掉最下面的兩個}就行