我是靠谱客的博主 默默帆布鞋,这篇文章主要介绍jquery 中 first 与 first-child选择器的区别,现在分享给大家,希望可以做个参考。

例子 html:

<body>
<table>
<tr><td></td></tr>
</table>
<table>
<tr><td></td></tr>
</table>
<div>
</div>
</body> 


$("table tr:first")  得到的是第一个table 中的 第一个 tr对象 ; 
$("table tr:first-child")  得到的是每个table 中的 第一个 tr对象 ; 


$("body  table:first) 得到的是第一个table r对象 ; 
$("body  table:first-child) 得到的是 一个 空的 jquery 对象;

并没有得到预想的第一个table,因为  body 的子标签 中 并不是 全部的table  ,还有 div  ,所以 就 得不到任何东西,$("table tr:first")  得到的是第一个table 中的 第一个 tr对象 是因为 table 中 直接子标签都是tr; 

最后

以上就是默默帆布鞋最近收集整理的关于jquery 中 first 与 first-child选择器的区别的全部内容,更多相关jquery内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(124)

评论列表共有 0 条评论

立即
投稿
返回
顶部