99770 2023-2-15 09:45
如何使用 JavaScript 設定幾秒後跳轉頁面
如果希望使用 JavaScript 來跳轉頁面,只需要用location.href即可達成,location接口表示連結的位置。 <br><br>幾秒後跳轉語法<br>有時候我們可能會希望在某些交互動作後實現「幾秒後跳轉」的功能,這時候只需要設定setTimeout即可。 <br><br>頁面上顯示倒數+跳轉頁面<br><br>如果希望在瀏覽器上顯示倒數秒數,可以將倒數秒數的結果寫在指定的元素裡,具體作法請參考以下範例。 <br><br>5秒後跳轉到新網站,會需要建立兩隻檔案, index.html 及 script.js<br>(1) index.html<br>[quote]<br><!DOCTYPE html><br><html lang="en"><br><head><br> <meta charset="UTF-8"><br> <meta http-equiv="X-UA-Compatible" c><br> <meta name="viewport" c><br> <script src="script.js" defer></script><br> <title>5秒後跳轉到新網站</title><br></head><br><body><br> <main> <br> <center>網頁即將在 <span id="timeBox"></span> 後跳轉到新網站</center><br> </main><br></body><br></html><br>[/quote]<br><br>(2) script.js<br>[quote]<br>// 設定秒數<br>var count = 5;<br>function countDown(){<br> // 將秒數寫在指定元素中<br> document.getElementById("timeBox").innerHTML= count;<br> // 每次執行就減1<br> count -= 1;<br> // 當 count = 0 時跳轉頁面<br> if (count == 0){<br> location.href="http://www.adj.idv.tw";<br> }<br> // 設定每秒執行1次<br> setTimeout("countDown()",1000);<br>}<br>// 執行 countDown<br>countDown();<br>[/quote]<br><br>變數說明:<br>var count:定義變數,變數可自訂。<br>document.getElementById("timeBox"):找到id為timeBox的元素。<br>innerHTML:將字串插入指定的元素之HTML中。<br>x -= y:相當於 x = x - y。<br>location.href:轉址<br>setTimeout:設定秒數(單位是毫秒)<br>("countDown()",1000):每秒執行一次 countDown()<br><br><br>這樣就可以囉!
jijenoh362 2023-5-12 14:34
https://cialistw.neocities.org/levitravardenafil.htm
https://cialistw.neocities.org/futures0913.html
https://cialistw.neocities.org/bladdercancer0927.html
https://cialistw.neocities.org/levitra.html
https://cialistw.neocities.org/kamagrashopee.htm
https://cialistw.neocities.org/tw2.html
https://cialistw.neocities.org/tw1.html
https://cialistw.neocities.org/ordinary0914.htm
https://cialistw.neocities.org/abdominalpain0928.html
https://cialistw.neocities.org/testosterone.htm
https://cialistw.neocities.org/tawinman.htm
https://cialistw.neocities.org/supercialis.html
https://cialistw.neocities.org/stenagra.html
https://cialistw.neocities.org/index.html
https://cialistw.neocities.org/prostatitis0929.html
https://cialistw.neocities.org/preferred0915.html
https://cialistw.neocities.org/google3f5f8dd0cb2a25e3.html
https://cialistw.neocities.org/extrasupertadarad.htm
https://cialistw.neocities.org/etmallcialis.html
https://cialistw.neocities.org/etcshopee.htm
https://cialistw.neocities.org/neurogenic0930.html
https://cialistw.neocities.org/edtreat.html
https://cialistw.neocities.org/treasury0916.html
https://cialistw.neocities.org/12.html
https://cialistw.neocities.org/11.html
https://cialistw.neocities.org/10.html
https://cialistw.neocities.org/strictureofureter0931.html
https://cialistw.neocities.org/1.html
https://cialistw.neocities.org/urineretention.html
https://cialistw.neocities.org/renalstone0917.html
https://cialistw.neocities.org/urine.html
https://cialistw.neocities.org/tw9.html
https://cialistw.neocities.org/disordersofprostate0932.html
https://cialistw.neocities.org/momoshopee.htm
https://cialistw.neocities.org/mansed.htm
https://cialistw.neocities.org/ureteralstone0918.html
https://cialistw.neocities.org/edcenforce.html
https://cialistw.neocities.org/urethritis0933.html
https://cialistw.neocities.org/tw8.html
https://cialistw.neocities.org/tw7.html
https://cialistw.neocities.org/tw6.html
https://cialistw.neocities.org/urinarycalculus0919.html
https://cialistw.neocities.org/tw5.html
https://cialistw.neocities.org/vesicalstone0934.html
https://cialistw.neocities.org/cialis20mg.html
https://cialistw.neocities.org/badliver.html
https://cialistw.neocities.org/apage.html
https://cialistw.neocities.org/contracture0920.html
https://cialistw.neocities.org/tw4.html
https://cialistw.neocities.org/tw3.html