zoukankan      html  css  js  c++  java
  • js之制作网页计时器

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>网页计时器</title>
    </head>
    
    <body>
    <input type="button" id="b1" value="阅览时间">
    
    <script>
    //判断是否小于0,如果小于,加60//
         function f(t) {
            if (t<0){
                a=t+60;
                return a
            }
            else {
                return t
            }
        }
    //获取起始时间//
        var n_time_H=new  Date().getHours();
        var n_time_m=new  Date().getMinutes();
        var n_time_s=new  Date().getSeconds();
    //获取变量//
        b1Elm=document.getElementById('b1');
        b1Elm.onclick=function () {
    //获取当前时间//
         var c_time_H=new  Date().getHours();
        var c_time_m=new  Date().getMinutes();
        var c_time_s=new  Date().getSeconds();
    //进行时间的计算//
        var temp_h=f(c_time_H-n_time_H);
        var temp_m=f(c_time_m-n_time_m);
        var temp_s=f(c_time_s-n_time_s);
    
    //进行判断与输出//
        if (!temp_h)
            {
                if(!temp_m){
                    alert('阅览时间:'+temp_s+'秒')
                }
                else{
                    alert('阅览时间:'+temp_m+'分'+temp_s+'秒')
            }
            }
        else {
            alert('阅览时间:'+temp_h+'小时'+temp_m+'分'+temp_s+'秒')
        }
        }
    </script>
    </body>
    </html>
    运行截图:
     
  • 相关阅读:
    [CQOI2017] 小Q的棋盘
    CF75D Big Maximum Sum
    Dockerfile
    docker镜像与容器的导出导入
    ubuntu安装glusterFS
    常用工具网站网址
    国内数据分析平台
    清理系统垃圾
    sql注入笔记
    shopify Liquid语言学习知识点总结
  • 原文地址:https://www.cnblogs.com/98WDJ/p/10673537.html
Copyright © 2011-2022 走看看