<!DOCTYPE html>
<html>
<head>
<title>JavaScript练习</title>
<script>
function displayDate() {
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>JavaScript显示时间练习</h1>
<p id="demo">显示时间的区域</p>
<button type="button" οnclick="displayDate()">显示时间</button>
</body>
<html>
<head>
<title>JavaScript练习</title>
<script>
function displayDate() {
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>JavaScript显示时间练习</h1>
<p id="demo">显示时间的区域</p>
<button type="button" οnclick="displayDate()">显示时间</button>
</body>
</html>
另一种写法
<!DOCTYPE html>
<html>
<head>
<title>JavaScript练习</title>
</head>
<body>
<script>
var d=new Date();
document.write(d);
</script>
</body>
</html>