用js 实现 在text文本框里动态显示当前时间 怎么实现那
用js 实现 在text文本框里动态显示当前时间 怎么实现那
帮帮忙啊!
------解决方案--------------------在JS里var当前日期,根据当前日期取到年月日。。。。有个setTimeOut吧,可以设置刷新时间间隔...
把取到的时间放到Text里就OK了
------解决方案--------------------setTimeout('changeDate()',1000); 1S调用一次changeDate()
------解决方案--------------------
------解决方案--------------------setInterval
------解决方案--------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body onload="timeYear()">
<SCRIPT language=JavaScript>
//调用函数时间显示在文本框中
function timeYear(){
var tmpDate=new Date();
var day;
switch(tmpDate.getDay())
{
case 0:
day="星期日";
break;
case 1:
day="星期一";
break;
case 2:
day="星期二";
break;
case 3:
day="星期三";
break;
case 4:
day="星期四";
break;
case 5:
day="星期五";
break;
case 6:
day="星期六";
break;
}
document.getElementById("time").value=tmpDate.getFullYear()+"-"+(tmpDate.getMonth()+1)+"-"+tmpDate.getDate()+" "+day+tmpDate.getHours()+":"+tmpDate.getMinutes()+":"+tmpDate.getSeconds();
}
setInterval("timeYear()",1000);
//-->
</SCRIPT>
<input type="text" id="time" name="time" disabled="disabled" size="30">
</body>
</html>
------解决方案--------------------HTML code
<html>
<head>
<script type="text/javascript">
function startClock()
{
setInterval(getTime, 1000);
}
function getTime()
{
var now = new Date();
document.getElementById('clock').value = now.getFullYear()
+ "-" + (now.getMonth() + 1)
+ "-" + now.getDate()
+ " " + now.getHours()
+ ":" + now.getMinutes()
+ ":" + now.getSeconds();
}
</script>
</head>
<body onload="startClock()">
<input id="clock" />
</body>
</html>