有人可以帮忙吗?我的时钟代码遇到了麻烦。 [英] Can someone help? I'm having a litte trouble with my clock code.

查看:94
本文介绍了有人可以帮忙吗?我的时钟代码遇到了麻烦。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

<br /><code><input name="time" type="text" value="<?php date('g:i:s A M, d Y')
?>" onload="setinterval(1000)"></code><br />{

我要做的是让输入代码每秒刷新一次,所以它就像一个正常的时钟}和{它正在做的只是保持:[2013年7月25日下午8:40:16]并且不自动更新。}提前感谢您的答案!

What I'm trying to do is make the input code refresh every second, so it works like a normal clock} and {what It's doing is just staying like: "[8:40:16 PM Jul 25, 2013]" and not auto-updating.} Thank you in advance for your answers!

推荐答案

首先,页面的PHP部分只被触发一次(当页面由网络服务器处理时)并且实际上不在你的htmlpage中。因此,除非你想要重新加载整个页面,否则你需要在javascript中进行操作。



我要做的是使用其中的clock元素制作一个div标签你的html代码如下:

First off the PHP part of the page is only fired once (when the page is processed by the webserver) and is not actually in you htmlpage. So unless you want the whole page to reload you need to do it in a javascript.

What I would do is make an div tag with the clock element in it in your html-code like this:
<div id="clock"></div>





并构建一个javascript类来处理实际的时钟:





and build a javascript class to handle the actual clock:

StartUp();

function UpdateClock() {
    var clockElement = document.getElementById('clock');
    var time = new Date();
    var hours = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
    var date = time.getMonth() + " " + time.getDate() + ", " + time.getFullYear();
    clockElement.innerHTML = hours + " " + date;
}

function StartUp() {
    intervalId = setInterval(UpdateClock, 1000);
}





应该这样做。小时和日期变量需要合成,但基本就是



WilyeECoyote



And that should do it. The hours and date variable needs to be formated ofcourse, but the basic is there

WilyeECoyote


你可以参考脚本网站 http://www.scripts.com/java-scripts/clock-scripts/ [ ^ ]。
You can refer the script site http://www.scripts.com/java-scripts/clock-scripts/[^] for any kind of code.


这篇关于有人可以帮忙吗?我的时钟代码遇到了麻烦。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆