jq index()用法

    xiaoxiao2022-07-02  114

    <!DOCTYPE html> <html lang="en"> <head>     <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>     <meta charset="UTF-8">     <title>元素选择器</title> </head>         <body>     <ul>         <li>             1         </li>         <li>             2         </li>         <li>             3         </li>         <li>             4         </li>     </ul>     <script type="text/javascript">         $(function(){             $("ul li").on("click",function(){                 var ind = $(this).index();                 alert(ind);                 $("ul li").removeClass("current");                 $(this).css("background-color","yellow");             })         }     </script> </body> </html>

     

    最新回复(0)