首页javascriptchildren_indexjQuery Selector - 如何选择具有一个跨度的第一个UL li项目

jQuery Selector - 如何选择具有一个跨度的第一个UL li项目

我们想知道如何选择具有一个跨度的第一个UL li项目。

<!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(){
    var itemName = $('ul li:first').find('a span').text();
    console.log(itemName)
});
</script>
</head>
<body>
  <ul>
    <li><a href="#"><span>item1</span></a></li>
    <li><a href="#"><span>item2</span></a></li>
  </ul>
</body>
</html>