1. 首页
  2. css

CSS#06:jQuery选择器扩展

jQuery可以选择CSS3可以选择的任何内容。但它不止于此!jQuery提供了许多额外的选择器(通过Sizzle选择器引擎),它们有时非常有用。例如,CSS具有属性选择器,允许您基于元素可能具有的任意属性来选择元素。例如:

There is a CSS selector we can use in jQuery to select that:
There are variations on the attribute selector, like instead of> you can do> to indicate \”starts with this value\”. But for some reason, CSS doesn\”t have>
There are lots of these selector extensions. A few we specifically talk about in this screencast:
– :eq() – a 0-indexed version of :nth-child()
– :even – shortcut for :nth-child(even)
– :gt(n) – select elements with a greater index than n. Also a shortcut for a more complex :nth-child() forumla.
Possibly the most useful selector extension of all is :has() – which limits the selection to elements which contain what you pass this pseudo selector (or is it a pseudo pseudo selector 🙂 It\”s likely that someday in the future CSS will have something like this for us (I think it\”s going to be like pre ! code),但那是一个很长的路要走。不幸的是,我没有在这个屏幕上为它做一个非常有说服力的论点,但你会知道什么时候你需要它!例如,\”Select all.module\”包含一个h3.sports条,诸如此类的东西。
如果您愿意,您还可以自己选择扩展。这是一篇关于这个的文章。示例是使:inview仅当元素在当前滚动位置的页面上可见时才选择该元素。它是这样的:
jQuery.extend扩展(jQuery.expr文件[\”:\”],{inview:function(el){var===windowTop->

CSS#06:jQuery选择器扩展 为WP2原创文章,链接:https://www.wp2.cn/css/css06jquery%e9%80%89%e6%8b%a9%e5%99%a8%e6%89%a9%e5%b1%95/