<span style="font-size:18px;"><html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"></span>
<span style="font-size:18px; white-space: pre;"></span><span style="font-size:32px;color:#ff0000;">//jQuery版本根據實際選擇</span><span style="font-size:18px;"> <script type="text/javascript" src="js/jquery-2.2.4.js"></script></head><body><ul> <li>John</li> <li>Karl</li> <li>Brandon</li></ul><ul> <li>Glen</li> <li>Tane</li> <li>Ralph</li></ul><ul> <li>Marry</li></ul><ul> <li>Jack</li></ul><script type="text/javascript"> /*1)迭代[each]每個ul中第1個li元素中的內容,索引從1開始 $("ul li:first-child").each(function(){ alert( $(this).text()); });*/ /*2)迭代每個ul中最後1個li元素中的內容,索引從1開始 $("ul li:last-child").each(function(){ alert($(this).text()); });*/ /*4)迭代每個ul中第2個li元素中的內容,索引從1開始 $("ul li:nth-child(2)").each(function(){ alert($(this).text()); });*/ //3)在ul中尋找是唯一子項目的li元素的內容 $("ul li:only-child").each(function(){ alert($(this).text()); });</script></body></html></span>