- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Documenttitle>
- head>
- <body>
- <button onclick="aaa()">按钮1button>
- <button onclick="bbb()">按钮2button>
- <script>
- let timer ;
- function aaa(){
- timer = setTimeout(function(){
- console.log("
5秒后看到我"
) - },5000);
- }
- function bbb(){
- clearTimeout(timer);
- }
- script>
- body>
- html>
- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Documenttitle>
- <style>
- div{
- height: 200px;
- width: 200px;
- border: 1px solid rgb(251, 115, 115);
- }
- style>
- head>
- <body>
- <a href="练习.html">再倒计时a>
- <button onclick="daojishi()">倒计时button>
- <div>div>
- <script>
- function daojishi() {
- let div = document.querySelector("div");
- let i = 5;
- let timer = setInterval(function() {
- div.innerHTML = `
${i}
`; - i--;
- if(i < 0){
- // clearInterval(timer);
- div.innerHTML = "
GO!!!
"; - return;
- }
- },900);
- console.log(i);
- }
- script>
- body>
- html>