Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use js to realize payment countdown to return home page

Shulou Source: shulou.com Published: 2022-06-02 23:28:39 10月01日 Update

This article mainly introduces "how to use js to achieve payment countdown to return to the home page". In daily operation, I believe that many people have doubts about how to use js to achieve payment countdown to return to the home page. Xiaobian consulted all kinds of information and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for everyone to answer the question of "how to use js to achieve payment countdown to return home page". Next, please follow the editor to study!

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

Index.html

The effect picture is as follows:

Document .wrapper {background-color:aquamarine; width: 300px; height: 300px; margin: 0 auto;} h3 {text-align: center;} button {text-align: center; margin-left: 68px } goods: smile Price: infinity payment method: Net order number: 123456789 cancel payment / / Logic: click the payment button to jump to the page / / get the second (the first is 0) tag marked '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') / / determine whether it is true, jump to if (res) {/ / directly use the html page in the directory, or enter other website links location.href = ". / return.html"}}

Return.html

Document .wrapper {width: 300px; height: 400px; margin: 0 auto;} .content {text-align: center } return to the home page immediately after 10 seconds of successful payment / / Logic: open the page and start the countdown _ window.onload = function () {/ / assign let timer = 10 first / / countdown / / Arrow function () = > {} = = function () {} setInterval () = > {timer--; document.getElementById ('countDown'). InnerText = timer / / when it is equal to 0, jump to the home page if (timer==0) {location.href = ". / index.html"}, 1000) } / / Click the button to immediately return to the home page document.getElementsByTagName ('button') [0] .onclick = function () {location.href = ". / index.html"}, the study on "how to use js to realize the payment countdown to return to the home page" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Payment home page countdown page learning button function more tag website logic help utility success next event price commodity effect effect effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux MariaDB Shulou Tech Info Xiaomi