zoukankan      html  css  js  c++  java
  • 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>
    </head>
    <body>
        <button id="bt1">开始</button>
        <button id="bt2"> 停止</button>
        <div>
            当前进度:<span id="sp1">  10%</span>
            <progress id="pr1" max="100" min="0" value="10"></progress>
        </div>
        <script>
            window.onload=function(){
                document.getElementById("sp1").innerText="0%";
                document.getElementById("pr1").value="0";
                let time=null;
                document.getElementById("bt1").onclick=function(){
                     if(time!=null) return;
                    time=setInterval(function(){
                        let i=parseInt(document.getElementById("pr1").value);
                        if(i==100 && time!=null)
                        {
                            clearInterval(time);
                            return;
                        }
                        i++;
                        document.getElementById("pr1").value=i;
                        document.getElementById("sp1").innerHTML=i.toString()+"%";
                    },1000)
                };
    
                document.getElementById("bt2").onclick=function(){
                    clearInterval(time);
                    time=null;
                    
                    // return;
                };
            };
        </script>
    
    </body>
    </html>
    

    运行结果


  • 相关阅读:
    君の名は~ 观后感
    dp1,明天补题解
    【bzoj1222】[HNOI2001]产品加工
    Daily~Miracles
    luogu 1273有线电视网
    luogu 1373
    codeforces 721C
    codeforces 706E
    The~Best~Chanteur~宇多田ヒカル
    codeforces706D
  • 原文地址:https://www.cnblogs.com/d534/p/15143990.html
Copyright © 2011-2022 走看看