特急求教高手如何在页面上动态显示时间

wxhbfmt 2005-05-30 04:06:30
小弟我正在做一个考试系统,要实现的功能是要在指定的时间内提交试卷,
也就是只要在页面上动态显示个时间就搞顶了,我用那个timer控件好象没用
在网上看了好多文章都是c#的,不会 ,我是用vb开发的,马上要交了
只有向个位大虾求教了
...全文
96 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
果果 2005-05-30
  • 打赏
  • 举报
回复
<head>
//第一步是把这个函数加在HEAD中
<script 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 + "年";
timeValue += ((month < 10) ? "0" : "") + month + "月";
timeValue += date + "日 ";
timeValue += (Day[day]) + " ";
timeValue += ((hours));
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
// timeValue += (hours < 12) ? "上午" : " 下午";
document.all.clock.innerText = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true
}//标准日期到中文日期的转化函数
function startclock () {
stopclock();
showtime()
}//打开闹钟函数
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
//第二步是在BODY中加上onLoad="startclock()"
<body leftmargin="0" topmargin="0" onLoad="startclock()" >
//第三步是在TD中,id="clock"
<table border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td id="clock"> </td>
</tr>
</table>
</body>

这个很好用的。

Nils 2005-05-30
  • 打赏
  • 举报
回复
用javascript比你在服务器端写这个好N倍.为什么非要用VB?
hugh828 2005-05-30
  • 打赏
  • 举报
回复
up
wxhbfmt 2005-05-30
  • 打赏
  • 举报
回复
各位大虾 我只知道用vb做哦,可以写个vb的吗??
january03 2005-05-30
  • 打赏
  • 举报
回复
在HTML选项
<asp: Label id ="time" runat="server"/>

在代码页:
void Page_Load()
{
//在前面写个循环,每秒刷新一次,循环我就不写了
time.text = DataTime.Now.ToString();
}
hackate 2005-05-30
  • 打赏
  • 举报
回复
<script language="JavaScript">
var timerID = null;
var timerRunning = false;

function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}

function startclock () {
stopclock();
showtime();}

function showtime () {

var timerID = null;
var timerRunning = false;

var now = new Date();
var year=now.getFullYear();
var month=now.getMonth();
var day=now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();

var timeValue=year;
timeValue+="-"+(month+1);
timeValue+="-"+day;

timeValue+=" "+hours+":";
timeValue +=minutes+":";
timeValue +=seconds;
document.all.控件ID.value=timeValue;

timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
</script>

上面有的错误
hackate 2005-05-30
  • 打赏
  • 举报
回复
用JS来实现,代码如下:
<script language="JavaScript">
var timerID = null;
var timerRunning = false;

function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}

function startclock () {
stopclock();
showtime();}

function showtime () {

var timerID = null;
var timerRunning = false;

var now = new Date();
var year=now.getFullYear();
var month=now.getMonth();
var day=now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();

var timeValue=year;
timeValue+="-"+(month+1);
timeValue+="-"+day;

timeValue+=" "+hours+":";
timeValue +=minutes+":";
timeValue +=seconds;
document.all.timeNow.value=timeValue;

timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function f()
{
document.all.你要显示在哪个控件的ID.value=document.all.timeNow.value;
}
</script>
wxhbfmt 2005-05-30
  • 打赏
  • 举报
回复
脚本是vb哦
Nils 2005-05-30
  • 打赏
  • 举报
回复
<SCRIPT language=javascript>
<!--
function Year_Month(){
var now = new Date();
var yy = now.getYear();
var mm = now.getMonth();
var mmm=new Array();
mmm[0]="January";
mmm[1]="February ";
mmm[2]="March";
mmm[3]="April";
mmm[4]="May";
mmm[5]="June";
mmm[6]="July";
mmm[7]="August";
mmm[8]="September";
mmm[9]="October";
mmm[10]="November";
mmm[11]="December";
mm=mmm[mm];
return(mm ); }
function thisYear(){
var now = new Date();
var yy = now.getYear();
return(yy ); }
function Date_of_Today(){
var now = new Date();
return(now.getDate() ); }
function CurentTime(){
var now = new Date();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000;
var clock = hh+':';
if (mm < 10) clock += '0';
clock += mm+':';
if (ss < 10) clock += '0';
clock += ss;
return(clock); }
function refreshCalendarClock(){
document.all.calendarClock1.innerHTML = Year_Month();
document.all.calendarClock2.innerHTML = Date_of_Today();
document.all.calendarClock3.innerHTML =thisYear();
document.all.calendarClock4.innerHTML = CurentTime(); }
document.write('<font id="calendarClock1" > </font> ');
document.write('<font id="calendarClock2" > </font>,');
document.write('<font id="calendarClock3" > </font> ');
document.write('<font id="calendarClock4" > </font>');
setInterval('refreshCalendarClock()',1000);
//-->
</SCRIPT>
<script language="javascript" src="./script/date.js"></script>

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧