<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
#div1{
width:500px;
height:100px;
background:#000;
margin:0 auto;
}
</style>
<script type="text/javascript">
window.onload=function(){
var divobj=document.getElementById('div1');
setInterval("settime()",1000);
function settime(){
var dd=new Date();
var t=dd.toLocaleString();
divobj.innerHTML=t;
}
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
哪里出错了?
错误:1,你的function settime()写进了onload方法里面,
2,background:#000;背景纯黑,啥也看不见,改为background:#fff;
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
#div1{
width:500px;
height:100px;
background:#fff;
margin:0 auto;
}
</style>
</head>
<body>
<div id="div1"></div>
</body>
</html>
<script type="text/javascript">
var divobj=document.getElementById('div1');
window.onload=function(){
setInterval("settime()",1000);
}
function settime(){
var dd=new Date();
var t=dd.toLocaleString();
divobj.innerHTML=t;
}
</script>