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.getFullYear();
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.getFullYear();
}
</script>