<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <button>點擊跳轉</button> <div></div> <script> var btn = document.querySelector('button'); btn.addEventListener('click', function () { // 注冊按鈕點擊事件 location.href = "http://www.baidu.com"; // 要跳轉到的地址 }); var div = document.querySelector('div'); var time = 5; // 這里設置自動跳轉的時間 function f() { if (time > 0) { div.innerHTML = time + "s后跳轉頁面"; time--; } else { location.href = 'http://www.baidu.com'; // 要跳轉到的地址 } } setInterval(f, 1000); // 計時器 </script> </body> </html>