/*var div1=document.getElementById('div1')
div1.onclick=letstart*/
当点击div1 时才会加载时间
我把这个注释掉了
改成页面加载 就调用这个函数 letstart()
下面是我修改的 你可以看下
<html>
<head>
<script type="text/javascript">
function showtime(){
var now=new Date()
var year=now.getFullYear()
var month=now.getMonth()+1
var day=now.getDate()
var hours=now.getHours()
var minutes=now.getMinutes()
var seconds=now.getSeconds()
time=year+'/'+month+'/'+day +'/'+hours+':'+minutes+':'+seconds
var div1=document.getElementById('div1')
div1.innerHTML=time
}
function letstart(){
taskId=setInterval(showtime,500)
}
window.onload=function(){
/*var div1=document.getElementById('div1')
div1.onclick=letstart*/
letstart()
}
</script>
</head>
<body style="font-size :30px">
<div id="div1" style="width:243pxheight:35pxborder :1px solid black background-color:grey" ></div>
</body>
</html>
<title>时间</title>
<script language="javascript">
//setTimeout("self.location.reload()",1000)
window.setInterval('showTime()',1000)
function showTime()
{
var enabled = 0
today = new Date()
var day
var date
if(today.getDay()==0) day = "星期日"
if(today.getDay()==1) day = "星期一"
if(today.getDay()==2) day = "星期二"
if(today.getDay()==3) day = "星期三"
if(today.getDay()==4) day = "星期四"
if(today.getDay()==5) day = "星期五"
if(today.getDay()==6) day = "星期六"
date = (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 " +
day+today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()
document.getElementById("time").innerHTML=date
}
</script>
<body onload="showTime()">
<div id="time"></div>
</body>
</html>
把上边的代码保存成html网页,然后打开就可以了!
<title>时间</title><script language="javascript">
//setTimeout("self.location.reload()",1000)
window.setInterval('showTime()',1000)
function showTime()
{
var enabled = 0
today = new Date()
var day
var date
if(today.getDay()==0) day = "星期日"
if(today.getDay()==1) day = "星期一"
if(today.getDay()==2) day = "星期二"
if(today.getDay()==3) day = "星期三"
if(today.getDay()==4) day = "星期四"
if(today.getDay()==5) day = "星期五"
if(today.getDay()==6) day = "星期六"
date = (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 " +
day+today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()
document.getElementById("time").innerHTML=date
}
</script>
<body onload="showTime()">
<div id="time"></div>
</body>
</html>
把上边的代码保存成html网页,然后打开就可以了!
今天是<script language="javascript">var mydate=new Date()
var mymonth=mydate.getMonth()+1
var myday= mydate.getDate()
var myyear= mydate.getYear()
document.write(myyear+"-"+mymonth+"-"+myday)</script>,欢迎访问XX网
把上面部分复制到记事本后,再从记事本直接复制到网页代码中(记事本过渡一下,是为了去掉所有格式),代码已测试过
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)