• js动态时间


    一.在<head></head>

    之间写入下面js代码

    <script type="text/javascript" language="JavaScript">
    var timerID = null
    var timerRunning = false
    function MakeArray(size) {
    this.length = size;
    for (var i = 1; i <= size; i++) {
    this[i] = "";
    }
    return this;
    }
    function stopclock() {
    if (timerRunning)
    clearTimeout(timerID);
    timerRunning = false
    }
    function showtime() {
    var now = new Date();
    var year = now.getYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var day = now.getDay();
    Day = new MakeArray(7);
    Day[0] = "星期天";
    Day[1] = "星期一";
    Day[2] = "星期二";
    Day[3] = "星期三";
    Day[4] = "星期四";
    Day[5] = "星期五";
    Day[6] = "星期六";
    var timeValue = "";
    timeValue += year+1900 + "年";
    timeValue += ((month < 10) ? "0" : "") + month + "月";
    timeValue += date + "日 ";
    timeValue += (Day[day]) + " ";
    timeValue += ((hours <= 12) ? hours : hours - 12);
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    timeValue += (hours < 12) ? "上午" : "下午";
    //document.getElementById("face").innerText = timeValue;
    document.getElementById("face").value = timeValue;
    timerID = setTimeout("showtime()", 1000);
    timerRunning = true
    }
    function startclock() {
    stopclock();
    showtime()
    }
    </script>

    二.在body中在你对应的位置添加以下代码

    <input  type="text" name="face" id="face" size="40" value=""  runat="server" style="border-color: #000080"/>

    切记id,name要和js中的getElementById()对应!

  • 相关阅读:
    不同版本strtotime("2016-09-04")输出不同问题
    Jquery,YUI这个著名js库名称作用的理解
    函数和方法
    js的关联数组
    windows信息
    改centos7的网卡名
    GIT命令
    安装时遇到:正在尝试其它镜像。 http://mirrors.btte.net/centos/7.2.1511/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#6
    本地怎样访问虚拟机上的服务器
    yolo
  • 原文地址:https://www.cnblogs.com/aiai-An/p/4441982.html
Copyright © 2020-2023  润新知