当前位置:   article > 正文

页面跳转倒计时_通过window的延时调用方法和location的href属性,在页面中进行倒计时,时间到之后页

通过window的延时调用方法和location的href属性,在页面中进行倒计时,时间到之后页

当我们支付完成时,会有一个成功支付的跳转页面,这时就会有一个跳转倒计时,倒计时结束后会跳转到指定页面。

效果

 

 

 完成此效果的代码如下

支付页面的代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>首页</title>
  8. <style>
  9. form{
  10. height: 250px;
  11. width: 300px;
  12. background-color: bisque;
  13. margin: 0 auto;
  14. padding: 10px;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <form>
  20. <p>商品:csdn课程</p>
  21. <p>原价:1980</p>
  22. <p>现价:0.99</p>
  23. <p>内容:HTML、CSS、JS</p>
  24. <p>地址:河北省唐山市</p>
  25. <button>取消</button>
  26. <button>支付</button>
  27. </form>
  28. <script> //是否确认支付的提示框
  29. document.getElementsByTagName('button')[1].onclick = function(){
  30. let re = window.confirm('请问您确定要支付吗?');
  31. if(re){
  32. location.href = './succ.html';
  33. }
  34. }
  35. </script>
  36. </body>
  37. </html>

跳转后的倒计时页面代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>支付成功</title>
  8. <style>
  9. span{
  10. font-size: 5em;
  11. color: aquamarine;
  12. }
  13. div{
  14. height: 250px;
  15. width: 300px;
  16. margin: 0 auto;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div>
  22. <h2>恭喜你支付成功</h2>
  23. <span id="sp">5</span>秒后自动返回首页面<br>
  24. <button>立即返回</button>
  25. </div>
  26. <script>
  27. window.onload = function(){
  28. let timer = 5;
  29. setInterval(() => {
  30. timer--;
  31. document.getElementById('sp').innerText = timer;
  32. if(timer==0){
  33. location.href = './跳转页面倒计时.html';
  34. }
  35. }, 1000);
  36. }
  37. document.getElementsByTagName('button')[0].onclick = function(){
  38. location.href = './跳转页面倒计时.html';
  39. }
  40. </script>
  41. </body>
  42. </html>

window.onload = function(){
    let timer = 5;
    setInterval(() => {
        timer--;
        document.getElementById('sp').innerText =  timer;  //倒计时与span中文本相联系
        if(timer==0){
            location.href = './跳转页面倒计时.html';
        }
    }, 1000);
}

此部分JavaScript代码为倒计时,也是关键部分。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/45077
推荐阅读
相关标签
  

闽ICP备14008679号