01-$(this).index()索引问题.html 504 B

1234567891011121314151617181920212223
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <script src="js/jquery.min.js"></script>
  8. </head>
  9. <body>
  10. <div>
  11. <h1>第一个h1</h1>
  12. <h1>第二个h1</h1>
  13. <p>屁1</p>
  14. <p>屁2</p>
  15. <p>屁3</p>
  16. </div>
  17. <script>
  18. $("div p").on("click", function() {
  19. console.log($(this).index());
  20. });
  21. </script>
  22. </body>
  23. </html>