<!DOCTYPE html> <html> <body> <p>假设 y=5,计算 x=y+2,并显示结果。</p> <button onclick="Suan()">计算</button> <p id="jieguo"></p> <script> function Suan(){ var y=5,x=y+2; document.getElementById('jieguo').innerHTML="x="+x; } </script> </body> </html>