html页面添加系统当前时间 15
我要在html页面用java显示系统当前时间,要求刷新页面时时间改变<html><head><scripttype="text/javascript">functions...
我要在html页面用java显示系统当前时间,要求刷新页面时时间改变
<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.getElementByld('div1');
div1.innerHTML=time;
}
function letstart(){
taskld=setlnterval(showtime,500);
}
window.onload=function(){
letstart();
}
</script>
</head>
<body style="font-size:30px;">
<div id="div1" style="width:243px;height:35px;border:1px solid black;background-color:grey;"></div>
</body>
</html>
上面这段代码我写在记事本里,保存成.html的文件,显示结果是一个灰色黑边的框,里面什么都没有
代码错在哪了,如果会的话帮我完整些一下吧 谢谢 展开
<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.getElementByld('div1');
div1.innerHTML=time;
}
function letstart(){
taskld=setlnterval(showtime,500);
}
window.onload=function(){
letstart();
}
</script>
</head>
<body style="font-size:30px;">
<div id="div1" style="width:243px;height:35px;border:1px solid black;background-color:grey;"></div>
</body>
</html>
上面这段代码我写在记事本里,保存成.html的文件,显示结果是一个灰色黑边的框,里面什么都没有
代码错在哪了,如果会的话帮我完整些一下吧 谢谢 展开
2个回答
展开全部
<script type="text/javascript">
//时间日期
$(document).ready(function(){
setInterval(showTime, 1000);
function timer(obj,txt){
obj.text(txt);
}
function showTime(){
var today = new Date();
var weekday=new Array(7);
weekday[1]="星期一"
weekday[2]="星期二"
weekday[3]="星期三"
weekday[4]="星期四"
weekday[5]="星期五"
weekday[6]="星期六"
weekday[0]="星期日"
var y=today.getFullYear()+"年";
var month=today.getMonth()+1+"月";
var td=today.getDate()+"日";
var d=weekday[today.getDay()];
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
timer($("#Y"),y);
timer($("#MH"),month);
timer($("#TD"),td);
timer($("#D"),d);
timer($("#H"),h+":");
timer($("#M"),m+":");
timer($("#S"),s);
}
function checkTime(i){
if(i<10){
i="0"+i;
}
return i;
}
})
</script>
<p class="date" style="float:right; margin:5px 10px; text-align:center;">
<strong id="Y"></strong>
<strong id="MH"></strong>
<strong id="TD"></strong>
<strong id="D"></strong><br>
<strong id="H"></strong>
<strong id="M"></strong>
<strong id="S"></strong>
</p>
用定时器,1秒刷一次
//时间日期
$(document).ready(function(){
setInterval(showTime, 1000);
function timer(obj,txt){
obj.text(txt);
}
function showTime(){
var today = new Date();
var weekday=new Array(7);
weekday[1]="星期一"
weekday[2]="星期二"
weekday[3]="星期三"
weekday[4]="星期四"
weekday[5]="星期五"
weekday[6]="星期六"
weekday[0]="星期日"
var y=today.getFullYear()+"年";
var month=today.getMonth()+1+"月";
var td=today.getDate()+"日";
var d=weekday[today.getDay()];
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
timer($("#Y"),y);
timer($("#MH"),month);
timer($("#TD"),td);
timer($("#D"),d);
timer($("#H"),h+":");
timer($("#M"),m+":");
timer($("#S"),s);
}
function checkTime(i){
if(i<10){
i="0"+i;
}
return i;
}
})
</script>
<p class="date" style="float:right; margin:5px 10px; text-align:center;">
<strong id="Y"></strong>
<strong id="MH"></strong>
<strong id="TD"></strong>
<strong id="D"></strong><br>
<strong id="H"></strong>
<strong id="M"></strong>
<strong id="S"></strong>
</p>
用定时器,1秒刷一次
追问
不好意思 我是新手 你说的我完全看不懂 野不知道要写在html的那块
你先帮我说一下我的代码错在哪里吧 然后怎么改
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询