VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > JavaScript教程 >
  • js实例之01支付后的10秒倒计时

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
这是一个通过js实现的支付后的页面,点击支付会跳出一个弹窗,提示你是否要确定支付,确定后进入付后界面,该页面有着10秒倒计时,计时结束后便会返回原界面。也可以选择立刻返回,来返回主页面<br data-filtered="filtered">第一个zhifu.html页面<br data-filtered="filtered"><!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>支付页面</title>
    <style>
        div {
            width: 200px;
            height: 280px;
            background-color: #eee;
            padding: 20px;
            margin: auto;
        }
        
        button {
            margin: 30px 25px;
        }
    </style>
</head>
 
<body>
    <div>
        <p>商品:web前端课程</p>
        <p>原价:1980元</p>
        <p>现价:1.98元</p>
        <p>内容:html、css、JavaScript</p>
        <p>地址:郑州升达经贸管理学院</p>
        <p>
            <button>取消</button>
            <button>支付</button>
        </p>
    </div>
    <script>
        //点击支付出现确认框
        document.getElementsByTagName('button')[1].onclick = function() {
            let res = window.confirm('您确认要支付吗?')
            if (res) {
                location.href = './ten.html'
 
            }
        }
    </script>
</body>
 
</html><br>第二个ten.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>10秒倒计时</title>
    <style>
        div {
            margin: 0 auto;
            width: 500px;
        }
        
        #jumpto {
            color: red;
            font-size: 30px;
        }
    </style>
</head>
 
<body>
    <div>
        <h2>恭喜您,支付成功</h2>
        <span id="jumpto">10</span>秒后自动返回首页
        <p><button>立刻返回</button></p>
    </div>
    <script>
        //加载页面时,应该触发定时器时间10s
        window.onload = function() {
            let timer = 10;
            setInterval(() => {
                timer--;
                document.getElementById('jumpto').innerHTML = timer;
                if (timer == 0) {
                    location.href = './zhifu.html';
                }
            }, 1000);
        }
        document.getElementsByTagName('button')[0].onclick = function() {
            location.href = './zhifu.html';
        }
    </script>
</body>
 
</html>

出处:https://www.cnblogs.com/Ldz123/p/17261329.html


相关教程