<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>