专注前端素材!
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>素材8网教程(study.sucai8.cn)</title> </head> <body> <p>假设 y=5,计算 x=y+2,并显示结果。</p> <button onclick="myFunction()">点击这里</button> <p id="demo"></p> <script> function myFunction(){ var y=5; var x=y+2; var demoP=document.getElementById("demo") demoP.innerHTML="x=" + x; } </script> </body> </html>
运行结果