前台JS:通过Hover(鼠标悬停事件)动态悬浮显示DIV的ID

HTML代码:定义两个DIV并设置大小宽度

<div id="Div1" class="div-list" style="width:20px; height:50px; border:1px solid #F00">
        <a>DIV1</a>
    </div>
      <div id="Div2" class="div-list1" style="width:20px; height:50px; border:1px solid #F00">
        <a>DIV2</a>
    </div>

JS代码:调用Hover事件并遍历所有DIV

<script type="text/javascript">
        $(function () { $("div").hover(function () { var id = $(this).attr("id"); alert(id); }) })
    </script>

效果图如下:鼠标悬浮显示ID

猜你喜欢

转载自blog.csdn.net/qq_42450386/article/details/86501685