Prototype使用指南之selector.js
Selector是利用css selector來匹配選擇頁面元素的,所以要理解Selector首先應(yīng)該對css selector有所理解,下面是css2 selector的語法,當(dāng)然很多瀏覽器只是支持其中的一部分,Prototype 中的Selector主要支持tag選擇器、class選擇器和id選擇器,還有屬性(attribute)選擇器,基本上包含我們平時所用的所有類型
The following table summarizes CSS2 selector syntax, 詳細(xì)的可以看http://www.w3.org/TR/REC-CSS2/selector.html:
Pattern | Meaning | Described in section |
---|---|---|
* | Matches any element. | Universal selector |
E | Matches any E element (i.e., an element of type E). | Type selectors |
E F | Matches any F element that is a descendant of an E element. | Descendant selectors |
E > F | Matches any F element that is a child of an element E. | Child selectors |
E:first-child | Matches element E when E is the first child of its parent. | The :first-child pseudo-class |
E:link E:visited | Matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited). | The link pseudo-classes |
E:active E:hover E:focus | Matches E during certain user actions. | The dynamic pseudo-classes |
E:lang(c) | Matches element of type E if it is in (human) language c (the document language specifies how language is determined). | The :lang() pseudo-class |
E + F | Matches any F element immediately preceded by an element E. | Adjacent selectors |
E[foo] | Matches any E element with the “foo” attribute set (whatever the value). | Attribute selectors |
E[foo=”warning”] | Matches any E element whose “foo” attribute value is exactly equal to “warning”. | Attribute selectors |
E[foo~=”warning”] | Matches any E element whose “foo” attribute value is a list of space-separated values, one of which is exactly equal to “warning”. | Attribute selectors |
E[lang|=”en”] | Matches any E element whose “l(fā)ang” attribute has a hyphen-separated list of values beginning (from the left) with “en”. | Attribute selectors |
DIV.warning | HTML only. The same as DIV[class~=”warning”]. | Class selectors |
E#myid | Matches any E element ID equal to “myid”. | ID selectors |
Selector中包含Selector對象和類,
Selector對象具有下面兩個方法:
match(element):元素是否與本selector匹配,在Element中已經(jīng)介紹了
findElements(parentNode):parentNode中所有匹配本selector的子孫元素列表
使用方法也很簡單 var s=new Selector(expression); s.match(element); s.findElements($(element)),其中expression可以是如下方式 "div"、"#id"、".class"、"div#id"、"div[attribute]"、"div[attribute=fff]"、"div[attribute!=sdf]"
其中Selector也有幾個靜態(tài)方法,它們分別是:
matchElements(elements, expression):返回elements中符合expression的元素列表
findElement(elements, expression, index):返回elements中符合expression的元素列表中索引為index的元素
findChildElements(element, expressions):找出element的子孫元素中符合expressions的元素列表,其中expressions是一個expression數(shù)組,其中的expression支持"div li.#id"形式
$$方法:只是簡單的調(diào)用return Selector.findChildElements(document, $A(arguments))
雖然Selector有這么多方法,但是大部分都是內(nèi)部調(diào)用的,我們一般都很少使用,因為我們有個一個方便的方法$$,對于絕大部分情況已經(jīng)足夠了- Prototype使用指南之dom.js
- Prototype使用指南之form.js
- 使用prototype.js進行異步操作
- 使用prototype.js 的時候應(yīng)該特別注意的幾個問題.
- Prototype1.6 JS 官方下載地址
- JQuery,Extjs,YUI,Prototype,Dojo 等JS框架的區(qū)別和應(yīng)用場景簡述
- JS 面向?qū)ο笾衿娴膒rototype
- javascript 進階篇3 Ajax 、JSON、 Prototype介紹
- 深入分析js中的constructor和prototype
- 為JS擴展Array.prototype.indexOf引發(fā)的問題探討及解決
- 解析jQuery與其它js(Prototype)庫兼容共存
- 判斷js中各種數(shù)據(jù)的類型方法之typeof與0bject.prototype.toString講解
- js中prototype用法詳細(xì)介紹
- js中繼承的幾種用法總結(jié)(apply,call,prototype)
- js使用Array.prototype.sort()對數(shù)組對象排序的方法
- 談?wù)刯s中的prototype及prototype屬性解釋和常用方法
相關(guān)文章
Prototype源碼淺析 Enumerable部分之each方法
在javascript中,根本找不到Enumerable的影子,因為這一塊是Prototype作者從Ruby中借鑒過來的。2012-01-01Prototype PeriodicalExecuter對象 學(xué)習(xí)
這個對象就是可以周期性的執(zhí)行某個方法,但是在它內(nèi)部維持了一個狀態(tài),可以防止由于某些原因一次調(diào)用沒執(zhí)行,然后下一次調(diào)用又來了,這樣會造成連續(xù)執(zhí)行兩次方法。上面的第二斷英文就是這個意思。2009-07-07不錯的一篇關(guān)于javascript-prototype繼承
不錯的一篇關(guān)于javascript-prototype繼承...2007-08-08使用prototype.js 的時候應(yīng)該特別注意的幾個問題.
使用prototype.js 的時候應(yīng)該特別注意的幾個問題....2007-04-04Prototype Function對象 學(xué)習(xí)
這個對象就是對function的一些擴充,最重要的當(dāng)屬bind方法,其中wrap方法也很重要,在類繼承機制里面就是利用wrap方法來調(diào)用父類的同名方法。2009-07-07