html元素,定义了页面元素的布局,button,字符串“当前时间”,字符串容器:当前最新时间
css呈现,button的样式,字的样式
js交互,








4.2html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>实时报时</title>
<link rel="stylesheet" href="./4.2.css">
<script src="./4.2.js"></script>
</head>
<body>
<div id="container">
<button onclick="start_time()" id="start">开始</button>
<p id="prefix">当前时间:</p>
<p id='time'></p>
</div>
</body>
<script type="text/javascript">
var refresh_id=0;
function start_time(){
var button=document.getElementById('start');
if (button.textContent=='开始'){
refresh_id=setInterval('refresh_time()',1);
button.textContent='停止';
} else {
button.textContent='开始';
clearInterval(refresh_id);
}
}
</script>
</html>4.2.css
#container{
margin-top: 200px;
margin-left: 500px;
}
#prefix{
font-weight: bold;
color: blue;
}
#time{
color: red;
}4.2.js
function refresh_time() {
var time=new Date();
document.getElementById('time').textContent=time.toString();
}
HTML, CSS, JS的关系