js to realize payment countdown and return to the home page

js to realize payment countdown and return to the home page

Payment countdown to return to the home page case introduction: bind a button on the home page to jump to another page, using simple js syntax, getElementsByTagName, location.href, etc.

index.html

The effect diagram is as follows:

<!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>
        .wrapper{
            background-color:aquamarine;
            width: 300px;
            height: 300px;
            margin: 0 auto;
        }
        h2{
            text-align: center;
        }
        button{
            text-align: center; 
            margin-left: 68px;
        }
    </style>
</head>
<body>
    <div class="wrapper">
      <h2>Product:smile</h2>
      <h2>Price:infinity</h2>
      <h2>Payment method:Net</h2>
      <h2>Order number:123456789</h2>
      <button>Cancel</button>
      <button>Pay</button>
    </div>
 
    <script>
        //Logic: Click the payment button to jump to the page //Get the second (the first is 0) tag named 'button', add a click event and bind a function document.getElementsByTagName('button')[1].onclick = function(){
            //Confirmation box before jump let res = window.confirm('Please confirm payment');
            //Judge whether it is true, jump if true if (res) {
                //Directly use the HTML page in the directory, or enter other website links location.href = "./return.html"
            }
        }
    </script>
</body>
</html>

return.html

<!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>
        .wrapper{
            width: 300px;
            height: 400px;
            margin: 0 auto;
        }
        .content{
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="content">
        <h2>Payment successful</h2>
        <span id="countDown">Return to home page in 10</span> seconds<button>Return immediately</button>
        </div>
    </div>
 
    <script>
        //Logic: The page opens and the countdown starts window.onload = function(){
            //First assign let timer = 10;
            //Countdown//arrow function()=>{} == function(){}
            setInterval(()=>{
                timer--;
                document.getElementById('countDown').innerText = timer;
                // Jump to the home page when it is equal to 0 if (timer==0) {
                    location.href = "./index.html"
                }
            },1000);
        }
        //Click the button to return to the home page immediatelydocument.getElementsByTagName('button')[0].onclick = function(){
            location.href = "./index.html"
        }
    </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:
  • javascript realizes 10-second countdown for payment
  • AngularJS payment countdown function implementation ideas
  • JavaScript high imitation Alipay countdown page and code implementation
  • js to create payment countdown page
  • Implementation example of JS payment page countdown

<<:  A brief discussion on which fields in Mysql are suitable for indexing

>>:  Example code for implementing the "plus sign" effect with CSS

Recommend

A brief discussion on the magical uses of CSS pseudo-elements and pseudo-classes

CSS plays a very important role in a web page. Wi...

How to install and uninstall open-vswitch in Linux

1. Compile and install ovs from source code: Inst...

Introduction to installing and configuring JDK under CentOS system

Table of contents Preface Check and uninstall Ope...

Solve the problem of Mac Docker x509 certificate

question Recently I needed to log in to a private...

A brief discussion on the calculation method of key_len in mysql explain

The MySQL explain command can analyze the perform...

Difference and principle analysis of Nginx forward and reverse proxy

1. The difference between forward proxy and rever...

Summarize the common properties of BigIn functions in JavaScript

Table of contents 1. Overview 2. Attributes 1. Ma...

Detailed tutorial on running Tomcat in debug mode in IDEA Maven project

1. Add the following dependencies in pom.xml <...

A brief discussion on order reconstruction: MySQL sharding

Table of contents 1. Objectives 2. Environmental ...

Pure CSS to achieve cool neon light effect (with demo)

I have recently been following the CSS Animation ...

Vue.js cloud storage realizes image upload function

Preface Tip: The following is the main content of...

The DOCTYPE mode selection mechanism of well-known browsers

Document Scope This article covers mode switching...

Vue+Element UI realizes the encapsulation of drop-down menu

This article example shares the specific code of ...

Detailed explanation of GaussDB for MySQL performance optimization

Table of contents background Inspiration comes fr...

In-depth analysis of MySQL index data structure

Table of contents Overview Index data structure B...