This article shares the specific code of javascript to realize the 10-second countdown of payment for your reference. The specific content is as follows The effect diagram is as follows: This case is actually very simple. As long as you master the onclick function in the basics of js and the use of timers , you can quickly achieve such an effect. Let's take a look at how to do it~ First, you need two HTML files. Use HTML and CSS to write the initial page effects in the two files. I won’t go into details here. For details, see the following code Let's talk about the effects that js needs to produce: 1. Click on Pay in page 1 to jump to another file This is the effect we need to do So how do we jump between two pages? => Use The timing effect is very simple. Just use The code is as follows: Page 1: <!DOCTYPE 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>Document</title> <style> #btn{ display: block; margin:130px auto; width: 300px; height: 100px; font-size:30px; } </style> </head> <body> <button id="btn">Pay</button> <script> let btn = document.getElementById("btn"); btn.onclick=function(){ let con = window.confirm("Are you sure?"); if(con){ location.href='./payment.html'; } } </script> </body> </html> Page 2: <!DOCTYPE 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>Document</title> <style> #spa { font-size: 20px; color: red; } #total { width: 200px; height: 200px; background-color: rgba(169, 169, 169, 0.315); margin: 40px auto; border-radius: 20px; padding: 20px; position:flex; flex-direction: column; text-align: center; } #total h3 { padding-top: 20px; } #total button { margin-top: 30px } </style> </head> <body> <div id="total"> <h3>Congratulations, your payment was successful! </h3> <div> <span id="spa">10</span> <span>Automatically return to the home page after seconds</span> </div> <button id="btn">Return now</button> </div> <script> var spa = document.getElementById("spa"); let t = 10; setInterval(() => { t--; spa.innerText = t; if (t == 0) { location.href = "./pay 10 seconds.html"; } }, 400); var btn = document.getElementById("btn"); btn.onclick=function(){ location.href="./Pay 10 seconds.html" rel="external nofollow" } </script> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: IE8 Developer Tools Menu Explanation
>>: Zabbix combined with bat script to achieve multiple application status monitoring method
1. After entering the container cat /etc/hosts It...
This tutorial shares the installation and configu...
This article is welcome to be shared and aggregat...
CSS style specifications 1. Class Selector 2. Tag...
When you first start learning Linux, you first ne...
Why use Server-Side Rendering (SSR) Better SEO, s...
This article shares the specific code of jQuery...
Preface The "destructuring assignment syntax...
Recently, I solved the problem of Docker and the ...
Table of contents Why choose react-beautiful-dnd ...
Table of contents 1. Characteristics of JS 1.1 Mu...
Let's try out nginx's reverse proxy here....
JS provides three methods for intercepting string...
Table of contents 1. Ref and reactive 1. reactive...
SSH public key authentication is one of the SSH a...