<!DOCTYPE html>
<html>
<body>
<button οnclick="myFunction()">点击这里</button>
<p id="demo"></p>
</html>
<html>
<body>
<button οnclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x="";var time=new Date().getHours();if (time<20){x="Good day";}document.write(Date()); //注意:如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖document.getElementById("demo").innerHTML=x;
}
</body></script>
</html>