HTML2-----点击gsgadg变色

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>童心少年</title>
      <style>
          p{
              color:red
          }
          </style>
  </head>
  <body>    
   <p style="color:blue">假设 y=5, 计算 x=y+2, 并显示结果 </p>
   <button onclick="myFunction()">点击这里</button>
   <p onclick="click1()" id="demo">gsgsdg</p>
    <script>
      function myFunction(){
          var x=5;
          var y=x+1;
          x=y;
          var demoP = document.getElementById("demo")
          demoP.innerHTML="x="+x;
      }
        function click1(){
        var demo=document.getElementById("demo")
            demo.style="color:blue";
        }
    </script>
  </body>
</html>

 

posted @ 2025-11-15 12:00  付书恒  阅读(3)  评论(0)    收藏  举报