js 页面显示8s后关闭
js 页面显示8s后关闭,页面显示秒数
<!DOCTYPE html> <html lang="zh_CN"> <head> <meta charset="UTF-8"> <title>定时</title> <script src="jquery-3.4.1.min.js"></script> <script> /** * 定时8s,页面显示秒数,八秒之后关闭 */ let time = 8; setInterval(function () { if (time <= 0) { window.close(); } else { document.getElementById('t').innerText = --time; } }, 1000) </script> </head> <body> <div id="test"> 页面将在<span id="t">8</span>秒后关闭 </div> </body> </html>