• js倒计时改进版


    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    </head>

    <body>
    <div><input id="time_h" type="text" value="" />点<input id="time_m" type="text" value=""/>分<input id="time_s" value="" type="text"/>秒<input onClick="djs()" type="button" value="开始"/></div>
    <div id="time"></div>
    <script>
    var oTime=document.getElementById("time");

    var sj=new Date;
    var time_h,time_m,time_s;
    document.getElementById("time_h").value=sj.getHours();
    document.getElementById("time_m").value=sj.getMinutes();
    document.getElementById("time_s").value=sj.getSeconds();
    function time(){
    var sj=new Date;
    var gs=time_h*60*60+time_m*60+time_s;
    var xs=sj.getHours()*60*60+sj.getMinutes()*60+sj.getSeconds();

    var c=gs-xs;

    if(c < 0){
    alert('输入无效值,请重新输入');
    clearInterval(t);
    oTime.innerHTML="";
    return;
    }
    var h_xiao=parseInt((gs-xs)/3600);
    var m_xiao=parseInt(((gs-xs)/60)%60);
    var s_xiao=(gs-xs)%60;
    oTime.innerHTML=h_xiao+":"+m_xiao+":"+s_xiao;
    console.log(sj);
    if(gs==xs){
    clearInterval(t);
    alert('时间到');
    }


    }

    function djs(){
    time_h=parseInt(document.getElementById("time_h").value);
    time_m=parseInt(document.getElementById("time_m").value);
    time_s=parseInt(document.getElementById("time_s").value);

    t=setInterval(function(){time();},1000);
    }</script>
    </body>
    </html>

    代码写的很烂,各位看官指教!

  • 相关阅读:
    jquery获取父元素或父节点的方法
    JS省份联级下拉框
    全国各省、市名称(包括县级市)
    让Vs2010支持 Css3+HTML5
    Sql Server 事务/回滚
    Windows.Forms Panel 动态加载用户控件 UserControl
    C/C++ 运算符 & | 运算
    WPF
    SQL Server 数据库定时自动备份【转】
    如何编写更棒的代码:11个核心要点
  • 原文地址:https://www.cnblogs.com/xurui01/p/3978682.html
Copyright © 2020-2023  润新知