Prototype 1.6 - Utility Mothed

Prototype 常用的方法

$(), $$(), $A(), $F(), $H(), $R(), $w()

Try.these(), document.getElementsByClassName()

 

$()方法

 

语法

$(id | element) -> HTMLElement

$((id | element)...) -> [HTMLElement...]

 

描述

If provided with a string, returns the element in the document with matching ID; otherwise returns the passed element. Takes in an arbitrary number of arguments. All elements returned by the function are extended with Prototype DOM extensions.

 

示例

function foo(element) {

    element = $(element);

}

 

$$()方法

 

语法

$$(cssRule...) -> [HTMLElement...]

描述

Takes an arbitrary number of CSS selectors (strings) and returns a document-order array of extended DOM elements that match any of them.

 

$$('div')

// -> all DIVs in the document.  Same as document.getElementsByTagName('div')!

$$('#contents')

// -> same as $('contents'), only it returns an array anyway.

$$('li.faux')

// -> all LI elements with class 'faux'

$$('#contents a[rel]')

// -> all links inside the element of ID "contents" with a rel attribute

$$('a[href="#"]')

// -> all links with a href attribute of value "#" (eyeew!)

$$('#navbar li', '#sidebar li')

// -> all links within the elements of ID "navbar" or "sidebar"

 

$A()

$A(iterable) -> actualArray

 

$F()方法

 

$F(element) -> value

 <body>

    <div id="one" class="foo">Single class name</div>

    <div id="two" class="foo bar thud">Multiple class names</div>

    <ul id="list">

      <li id="item_one" class="thud">List item 1</li>

      <li>List item 2</li>

      <li id="item_two" class="thud">List item 3</li>

    </ul>

  </body>

 

  document.getElementsByClassName('foo');

  // -> [HTMLElement, HTMLElement] (div#one, div#two)

  document.getElementsByClassName('thud');

  // -> [HTMLElement, HTMLElement, HTMLElement] (div#two, li#item_one, li#item_two);

  document.getElementsByClassName('thud', $('list'));

  // -> [HTMLElement, HTMLElement] (li#item_one, li#item_two)

 

 

Try.these()方法

getTransport: function() {

return Try.these(

function() { return new XMLHttpRequest() },

function() { return new ActiveXObject('Msxml2.XMLHTTP') },

function() { return new ActiveXObject('Microsoft.XMLHTTP') }

  ) || false;

}

posted @ 2007-11-23 00:35  Yoshow  阅读(287)  评论(0编辑  收藏  举报