<ul> <li>1</li> <li>2</li> <li>3</li> </ul>
<script> console.log($(‘ul li:first‘)); console.log($("ul>li:first")); console.log($(‘ul‘).children(‘li‘).get(0)); console.log($(‘ul‘).children(‘li‘).eq(0)); console.log($(‘ul‘).children(‘li‘).first()); console.log($(‘ul‘).find(‘li‘).get(0)); console.log($(‘ul‘).find(‘li‘).eq(0)); console.log($(‘ul‘).find(‘li‘).first()); console.log($(‘ul‘).children(‘:first‘)); console.log($(‘ul‘).children(‘li:first‘)); console.log($(‘ul‘).children(‘li:first-child‘)); console.log($(‘ul‘).children(‘li:nth-child(1)‘)); console.log($(‘ul‘).find(‘:first‘)); console.log($(‘ul‘).find(‘li:first‘)); console.log($(‘ul‘).find(‘li:first-child‘)); console.log($(‘ul‘).find(‘li:nth-child(1)‘)); </script>
注意:.get()得到DOM对象,而.eq()、.first()、.children()、.find()等得到jQuery对象
原文链接:https://blog.csdn.net/PrisonersDilemma/article/details/90259555
原文地址:https://www.cnblogs.com/firstcsharp/p/12148710.html
时间: 2024-10-06 18:44:49