目的:

鼠标放到a链接上,显示二维码(添加show类名,去掉hide类名)

鼠标移开a链接,隐藏二维码(添加hide类名,去掉show类名)

代码如下:

<body>
<div class="nodeSmall" >
<a href="#"></a>
<div class="erweima hide" >
<img src="../images/456.png" alt=""/>
</div>
</div>

<script type="text/javascript">
//需求:鼠标放到a链接上,显示二维码(添加show类名,去掉hide类名)
//      鼠标移开a链接,隐藏二维码(添加hide类名,去掉show类名)
//      步骤:
//      1.获取事件源和相关元素
var a = document.getElementsByTagName("a")[0];
var div = document.getElementsByClassName("erweima")[0];
//      2.绑定事件
a.onmouseover = function fn1(){
 div.className = "erweima show";

}
a.onmouseout = function fn2(){
    div.className = "erweima hide";
}
//      3.书写事件绑定程序

</script>
</body>

 

相关文章:

  • 2021-09-16
  • 2022-12-23
  • 2021-11-22
  • 2021-09-12
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2021-06-06
  • 2021-09-24
  • 2021-06-14
  • 2022-01-30
  • 2021-12-03
  • 2021-12-27
  • 2021-11-19
相关资源
相似解决方案