什么是选择器引擎?
我已经看到 John Resig 的快速新选择器引擎名为 Sizzle 的新闻突然出现很少有地方,但我不知道选择器引擎是什么,也没有任何文章给出它是什么的解释。 我知道 Resig 是 jQuery 的创建者,Sizzle 是 Javascript 中的东西,但除此之外我不知道它是什么。 那么,什么是选择器引擎?
谢谢!
I've seen news of John Resig's fast new selector engine named Sizzle pop up in quite a few places, but I don't know what a selector engine is, nor have any of the articles given an explanation of what it is. I know Resig is the creator of jQuery, and that Sizzle is something in Javascript, but beyond that I don't know what it is. So, what is a selector engine?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
选择器引擎是一种遍历 DOM 查找特定元素的方法。
内置选择器引擎的示例:
A selector engine is a way to traverse the DOM looking for a specific element.
An example of a built in selector engine:
此外,Sizzle 是 John Resig 目前正在开发的引擎,旨在取代 jQuery 已经很棒的选择器引擎。
Also, Sizzle is the engine John Resig is working on currently to replace jQuery's already fantastic selector engine.
选择器引擎用于查找文档中的元素,其方式与 CSS 样式表相同。 目前只有 Safari 具有内置的 querySelectorAll 函数来执行此操作。 对于其他浏览器,您必须使用外部 JavaScript 实现作为 LlamaLab Selector 或 Sizzle。
A selector engine is used to find elements in a document, in the same way as CSS stylesheets does. Currently only Safari has the built-in querySelectorAll function which does just that. With other browser you have to use external JavaScript implementations as LlamaLab Selector or Sizzle instead.
选择器引擎是一个 JavaScript 库,允许您使用某种字符串来选择 DOM 树中的元素来识别它们(想想 DOM 元素的正则表达式)。 大多数选择器引擎使用 CSS3 选择器语法的某些变体,因此,例如,您可以编写如下内容:
使用类firstParagraph 选择文档中的所有 P 元素。
一些选择器引擎还支持 XPath 的部分实现,甚至一些自定义语法。 例如,jQuery 允许您编写:
选择文档中登录表单中所有选中的复选框。
A selector engine is a JavaScript library that lets you select elements in the DOM tree using some kind of string for identifying them (think regular expressions for DOM elements). Most selector engines use some variation of the CSS3 selectors syntax so, for example, you can write something like:
to select all P elements in the document with class firstParagraph.
Some selector engines also support a partial implementation of XPath, and even some custom syntaxes. For example, jQuery lets you write:
To select all checked check boxes in the login form in the document.
选择器引擎用于基于某种查询(通常是 CSS 语法或类似语法)来查询页面 DOM 中的特定元素。
例如,这个 jQuery:
将搜索并返回所有的
优化选择器引擎是一件大事,因为您使用这些框架执行的几乎每个操作都基于某种 DOM 查询。
A selector engine is used to query a page's DOM for particular elements, based on some sort of query (usually CSS syntax or similar).
For example, this jQuery:
Would search for and return all of the <div> elements on the page. It uses jQuery's selector engine to do that.
Optimizing the selector engine is a big deal because almost every operation you perform with these frameworks is based on some sort of DOM query.