蓝宇轩
[javascript]日期时间动态-随便写的;

本帖最后由 蓝宇轩 于 2012-8-11 15:11 编辑

[mw_shl_code=xhtml,true]<!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">

*本站禁止HTML标签噢*

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

*本站禁止HTML标签噢* 时间</title>

<style type="text/css">

body{ background:#CCC;}

#mydiv{height:35px;}

</style>

</head>

*本站禁止HTML标签噢*

<div id="mydiv"></div>

</body>

</html>

<script type="text/javascript">

function $$(id){

return document.getElementById(id);//用它来寻找到指定id的div;

}

function datetime(){

var dt=new Date();//定义一个日期对象;

var dttime=dt.getFullYear()+"-";//将时期对象的"年"填充到dttime里;用"-"字符串分开;

dttime+=dt.getMonth()+1+"-";//将时期对象的"月"填充到dttime里;

dttime+=dt.getDate()+"-";//将时期对象的"日"填充到dttime里;

dttime+=dt.getHours()+"-";//将时期对象的"小时"填充到dttime里;

dttime+=dt.getMinutes()+"-";//将时期对象的"分"填充到dttime里;

dttime+=dt.getSeconds();//将时期对象的"秒"填充到dttime里;

$$("mydiv").innerHTML=dttime;//将dttime填充到Div(mydiv)的内容里;

setTimeout("datetime()",1000);//每隔1000毫秒(1秒)执行一次上面的函数;时间就在逐渐更新了;

}

window.onload=datetime;//窗体打开就执行;

</script>[/mw_shl_code]

one262616
one262616回复给帖子:4952927
展开Biu

好东西!!正需要!!!

[查看全文]