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>
    运行截图:
     
  • 相关阅读:
    窗口宽高 滚动条滚动距离 元素的文档坐标和窗口坐标
    parentNode parentElement childNodes children
    ffmpeg 提取mp3
    Linux修改时区的正确方法
    pip
    wireguard
    Nextcloud挂载谷歌云盘搭建
    ts合并
    screen
    google drive
  • 原文地址:https://www.cnblogs.com/98WDJ/p/10673537.html
Copyright © 2011-2022 走看看