java script 点击 div背景变化

<style type="text/css">
  #aa{
  width: 100px;
  height: 50px;
  border: 1px solid grey;
  text-align: center;
  line-height: 50px;
  border-radius: 5px;
   
  color: #0000FF;
  }
  #aa:hover{
  cursor: pointer;
  }
  .a1{
  width: 200px;
  height: 200px;
  background-color: red;
  }
  .a2{
  width: 300px;
  height: 300px;
  background-color: #0000FF;
  border-radius: 20px;
  }
  </style>

 

div id="aa">
  点击
  </div>
  <div class="a1"></div>
<script type="text/javascript">
  var aa = document.getElementById("aa")
  var a1 = document.getElementsByClassName("a1")
   
  aa.onclick = function(){
  a1[0].className = "a2"
  }
  </script>
posted @   猫java猫  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示