1
<p id="demo">单击按钮显示此时的小时字段:</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var d = new Date();
6
var x = document.getElementById("demo");
7
x.innerHTML = d.getHours();
8
}
9
</script>
<p id="demo">单击按钮显示此时的小时字段:</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML = d.getHours();
}
</script>