:last選擇器選擇最后匹配的元素。
這通常與另一個(gè)選擇器一起使用,以選擇組中的最后一個(gè)元素(如以下示例中所示)。
注意:: last選擇器只能選擇一個(gè)元素。
使用:last-child選擇器來(lái)選取屬于其父元素的最后一個(gè)子元素。
$(":last")選擇最后一段:
$(document).ready(function(){
$("p:last").css("background", "coral");
});測(cè)試看看?/?選擇最后一個(gè)列表項(xiàng):
$(document).ready(function(){
$("li:last").css("background", "coral");
});測(cè)試看看?/?選擇最后一個(gè)表行:
$(document).ready(function(){
$("tr:last").css("background", "coral");
});測(cè)試看看?/?顯示:last和:last-child選擇器之間的區(qū)別:
$(document).ready(function(){
$("#btn1").click(function(){
$("p:last").css("background-color", "coral");
});
$("#btn2").click(function(){
$("p:last-child").css("background-color", "lightgreen");
});
});測(cè)試看看?/?