用 juqery 为 div 绑定点击事件来获取每个 div 的索引为例:
html部分的代码如下:
<div style="width: 100px; height: 100px; background: pink;">div1</div><br/> <div style="width: 100px; height: 100px; background: pink;">div2</div><br/> <div style="width: 100px; height: 100px; background: pink;">div3</div><br/> <div style="width: 100px; height: 100px; background: pink;">div4</div><br/> <div style="width: 100px; height: 100px; background: pink;">div5</div><br/> <script src="js/jquery-3.3.1.js"></script>