美文网首页demo
JavaScript 实现简单倒计时功能

JavaScript 实现简单倒计时功能

作者: 小小前端搬运工 | 来源:发表于2022-03-24 22:12 被阅读0次

    confirm.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            div{
                width: 200px;
                height: 280px;
                background-color: #eee;
                padding: 20px;
                margin: 0 auto;
            }
            button{
                margin: 30px 25px;
            }
        </style>
    </head>
    <body>
        <div>
            <p>商品:Web前端课程</p>
            <p>原价:1980元</p>
            <p>现价:1.98元</p>
            <p>内容:HTML、CSS、JS</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 = './succ.html'
                }
            }
        </script>
    </body>
    </html>
    

    succ.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</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>
            window.onload = function () {
                let timer = 10
                setInterval(() => {
                    timer--;
                    document.getElementById('jumpTo').innerText = timer;
                    if(timer == 0){
                        location.href = './confirm.html'
                    }
                }, 1000);
            }
            document.getElementsByTagName('button')[0].onclick = function(){
                location.href = './confirm.html'
            }
        </script>
    </body>
    </html>
    

    相关文章

      网友评论

        本文标题:JavaScript 实现简单倒计时功能

        本文链接:https://www.haomeiwen.com/subject/klnljrtx.html