19

从 jquery.com 下载的最新 jquery 1.4.2 也带有 Sizzle.js。

我可以如何从包含的 Sizzle.js 中获得什么好处?

Sizzle.js 是一个独立的库吗?

为什么它包含在 jquery 库中,出于什么目的?

/*!
 * jQuery JavaScript Library v1.4.2
 * http://jquery.com/
 *
 * Copyright 2010, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Includes Sizzle.js
 * http://sizzlejs.com/
 * Copyright 2010, The Dojo Foundation
 * Released under the MIT, BSD, and GPL Licenses.
 *
 * Date: Sat Feb 13 22:33:48 2010 -0500
 */

虽然这在 sizzle.js 网站上有所提及

完全独立(无库依赖)

4

4 回答 4

33

Sizzle.js is a JavaScript library that implements a "CSS selector engine designed to be easily dropped in to a host library." jQuery uses it internally for its CSS selection needs. If you wanted a CSS engine and had no need for all the other JavaScript benefits of jQuery, you could use Sizzle.js separately.

于 2010-05-04T07:32:14.087 回答
13

OK, it was actually pretty unclear what sizzle.js was to me. Basically, what it does is allows you to use javascript on 'selectors', that is, classes, IDs, DOM elements, etc... So when you use this in jQuery:

$('div')

That's sizzle.js at work, making that element available to javascript.

I hope I got that all right :)

于 2013-02-08T18:54:24.090 回答
5

jQuery 需要嘶嘶声才能运行。您可以利用工作中的 javascript 库。

于 2010-05-04T04:56:45.040 回答
4

这是资源:

http://wiki.github.com/jeresig/sizzle/

选择器功能

* CSS 3 Selector support
* Full Unicode support
* Escaped selector support #id\:value
* Contains text :contains(text)
* Complex :not :not(a#id)
* Multiple :not :not(div,p)
* Not attribute value [name!=value]
* Has selector :has(div)
* Position selectors :first, :last, :even, :odd, :gt, :lt, :eq
* Easy Form selectors :input, :text, :checkbox, :file, :password, :submit, etc
* Header selector :header

代码特点

* Provides meaningful error messages for syntax problems
* Uses a single code path (no XPath)
* Uses no browser-sniffing
* Caja-compatible code
于 2010-05-04T04:56:42.387 回答