小白教程
所有教程
关于
Search
172.70.131.119
172.70.131.119
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Sel lastchild”的源代码
本页内容
上一节:
Sel_firstoftype
下一节:
Sel_lastoftype
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE::last-child}}[[Category:jquery ref selectors|13]] = jQuery :last-child 选择器 = [[jquery ref selectors|jQuery 选择器]] 选取属于其父元素的最后一个 <p> 的子元素: <sample title="" desc="" lang="html" hererun="1"> $("p:last-child") </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:last-child").css("background-color","yellow"); }); </script> </head> <body> <p>body 中第一个段落。</p> <div style="border:1px solid;"> <p>div 中第一个段落。</p> <p>div 中的最后一个段落。</p> </div><br> <div style="border:1px solid;"> <p>另一个 div 中第一个段落。</p> <p>另一个 div 中的最后一个段落。</p> <span>这是一个 span 元素。</span> </div> <p>body 中最后一个段落。</p> </body> </html> </run> == 定义和用法 == :last-child 选择器选取属于其父元素的最后一个子元素。 '''提示:'''请使用 [[sel firstchild|:first-child]] 选择器来选取属于其父元素的第一个子元素。 == 语法 == $(":last-child") == 尝试一下 - 实例 == [[try.php?filename=tryjquery_sel_lastchild2|选取所有 <div> 元素的最后一个 <p> 元素]] 如何选取所有 <div> 元素的最后一个 <p> 元素。 [[try.php?filename=tryjquery_sel_lastchild_last|:last 和 :last-child 之间的不同]] 演示 :last 和 :last-child 选择器之间的不同。 [[try.php?filename=tryjquery_sel_lastoftypediff|:last、:last-child 和 :last-of-type 之间的不同]] 演示 :last、:last-child 和 :last-of-type 选择器之间的不同。 [[jquery ref selectors|jQuery 选择器]]
返回至“
Sel lastchild
”。
上一节:
Sel_firstoftype
下一节:
Sel_lastoftype