首页javascriptuljQuery HTML Element - 如何得到UL项索引

jQuery HTML Element - 如何得到UL项索引

我们想知道如何得到UL项索引。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){
   console.log( $('ul li.active').index() + 1 );
});
</script>
</head>
<body>
  <ul>
    <li>1</li>
    <li class="active">2</li>
    <li>3</li>
    <li>4</li>
    <ul>
</body>
</html>