ceil [1.6.0]
ceil() -> Number
返回大于等于当前 Number 对象的最小整数值。
Math.ceil 的实例方法版本。
样例
Math.ceil(4.1) //-> 5
(4.1).ceil() //-> 5
(-4.1).ceil() //-> -4
eachSlice
eachSlice(size[, iterator = Prototype.K[, context]]) -> [slice...]
根据指定的大小对 Enumerable 中的元素进行分组,最后一组元素的个数可能小于指定的个数。
有时需要将一个集合划分为多个尺寸大致相同的分组。例如可能需要将集合中的数据显示为多列,或一些其它样式的布局。 也可能需要依次传入多组数据到后端进行处理(因为一些后端软件会对每次传入的数据个数进行硬编码限制),那么你应该会喜欢上 eachSlice,如果每个分组的尺寸必须完全相同,请使用 inGroupsOf。
可选的 context 参数是 iterator 要绑定的对象,若设定该参数,iterator 中的 this 关键字将指向 context 对象。
样例
var students = ...
replace
replace(element[, html]) -> HTMLElement
使用 html 参数指定的内容替换 element,返回被替换的 element。
译注:该方法类似于 IE 下的 element.outerHTML = html
当用于 Opera 9 的 input 元素时,若将 replace 当作实例的方法调用(如: $('foo').replace('<p>Bar</p>')),会引发错误。在 Web Forms 2 草案中,replace 是 input 的一个保留属性。在这种情形下,请使用一般的版本( Element.replace('foo', '<p>Bar</p>'))。
html 参数可以是纯文本,一个 HTML 片断或者任意具有 toString 方法的 JavaScript 对象。
如果 html 参数中包括 <script> 标签,在 e...
immediateDescendants [deprecated]
immediateDescendants(element) -> [HTMLElement...]
获取元素的直接后代(即子元素),返回一个数组,数组中的元素已经过 扩展。
在 Prototype 1.6 中,不推荐使用 Element#immediateDescendants,建议采用更友好的 Element#childElements 方法。
返回的数组成员按照元素在页面中的顺序进行排列(例如:索引 0 表示最顶部的子元素)。
注意:所有 Prototype 的 DOM 扩展方法均忽略文本节点,仅返回元素节点。
样例
<div id="australopithecus">
<div id="homo-erectus">
<div id=&qu...
firstDescendant [1.5.1]
firstDescendant(element) -> HTMLElement
返回第一个子元素。与 DOM 属性 firstChild 不同,firstChild 返回任意类型的节点(在很多情形下, 经常是一个空白文本节点[译注:这种情况在 Firefox 中较为常见])。
样例
<div id="australopithecus">
<div id="homo-erectus"><!--Latin is super -->
<div id="homo-neanderthalensis"></div>
<div id="homo-sapiens"></div>
</div>
</div>
$('australopithecus').firstDescendant();
// -> div#homo-herec...
descendants
descendants(element) -> [HTMLElement...]
返回 element 的所有后代节点,结果为一个数组,数组元素已经过 扩展。
注意:所有 Prototype 的 DOM 扩展方法均忽略文本节点,仅返回元素节点。
样例
<div id="australopithecus">
<div id="homo-herectus">
<div id="homo-neanderthalensis"></div>
<div id="homo-sapiens"></div>
</div>
</div>
$('australopithecus').descendants();
// -> [div#homo-herectus, div#homo-neanderthalensis, div#homo-sapiens]
$('homo-sapiens').descendants();...
descendantOf
descendantOf(element, ancestor) -> Boolean
判断 element 是否是参数 ancestor 指定元素的后代节点。
因为 Element.descendantOf 内部对 ancestor 应用了 $(),所以参数 ancestor 既可以是元素,也可以是元素的 ID。
样例
<div id="australopithecus">
<div id="homo-herectus">
<div id="homo-sapiens"></div>
</div>
</div>
$('homo-sapiens').descendantOf('australopithecus');
// -> true
$('homo-herectus').descendantOf('homo-sapiens');
// -> false
...
cleanWhitespace
cleanWhitespace(element) -> HTMLElement
移除元素中所有仅包含空白的文本节点,返回移除空白文本节点后的元素。
译注:所谓空白文本节点,是根据 XML 中的概念得来的,例如,有以下 HTML 代码:
<div>
<p>第一段</p>
</div>
<div> 的子节点(element.childNodes)包括 <p> 和空白文本节点(对于空白文本节点,各种浏览器的处理方式不一样), 这些空白文本节点有时对处理节点的顺序关系会造成影响,如上述 HTML 代码中我们通常认为 <p> 没有前导和后继兄弟节点, 但因为空白文本节点的干扰,程序可能会认为 <p> 有一个前导兄弟节点和一个后继兄...
ancestors(element) -> [HTMLElement...]
返回 element 的所有先代节点(父节点、父节点的父节点...一直到最顶层节点),结果为一个数组,数组元素已经过 扩展。
返回数组的第一个元素是 element 的直接先代节点(即 parentNode),第二个元素是它的祖父节点, 依此类推,直到 html 元素。html 总是数组的最后一个成员,除非你显式查找它的先代节点。 但是你不愿意这么做,不是吗?
注意:所有 Prototype 的 DOM 扩展方法均忽略文本节点,仅返回元素节点。
样例
<html>
[…]
<body>
<div id="father">
<div id="kid"> </div>
</div>
</bo...
replace(element[, html]) -> HTMLElement
使用 html 参数指定的内容替换 element,返回被替换的 element。
译注:该方法类似于 IE 下的 element.outerHTML = html
当用于 Opera 9 的 input 元素时,若将 replace 当作实例的方法调用(如: $('foo').replace('<p>Bar</p>')),会引发错误。在 Web Forms 2 草案中,replace 是 input 的一个保留属性。在这种情形下,请使用一般的版本( Element.replace('foo', '<p>Bar</p>'))。
html 参数可以是纯文本,一个 HTML 片断或者任意具有 toString 方法的 JavaScript 对象。
如果 html 参数中包括 <script> 标签,在 element 被替换...
immediateDescendants(element) -> [HTMLElement...]
获取元素的直接后代(即子元素),返回一个数组,数组中的元素已经过 扩展。
在 Prototype 1.6 中,不推荐使用 Element#immediateDescendants,建议采用更友好的 Element#childElements 方法。
返回的数组成员按照元素在页面中的顺序进行排列(例如:索引 0 表示最顶部的子元素)。
注意:所有 Prototype 的 DOM 扩展方法均忽略文本节点,仅返回元素节点。
样例
<div id="australopithecus">
<div id="homo-erectus">
<div id="homo-neanderthalensis"></div>
<div id="ho...
firstDescendant(element) -> HTMLElement
返回第一个子元素。与 DOM 属性 firstChild 不同,firstChild 返回任意类型的节点(在很多情形下, 经常是一个空白文本节点[译注:这种情况在 Firefox 中较为常见])。
样例
<div id="australopithecus">
<div id="homo-erectus"><!--Latin is super -->
<div id="homo-neanderthalensis"></div>
<div id="homo-sapiens"></div>
</div>
</div>
$('australopithecus').firstDescendant();
// -> div#homo-herectus
// DOM 的 firstChild 属性返回任意类型的...
descendants(element) -> [HTMLElement...]
返回 element 的所有后代节点,结果为一个数组,数组元素已经过扩展。
注意:所有 Prototype 的 DOM 扩展方法均忽略文本节点,仅返回元素节点。
样例
<div id="australopithecus">
<div id="homo-herectus">
<div id="homo-neanderthalensis"></div>
<div id="homo-sapiens"></div>
</div>
</div>
$('australopithecus').descendants();
// -> [div#homo-herectus, div#homo-neanderthalensis, div#homo-sapiens]
$('homo-sapiens').descendants();
// -> []
...
descendantOf(element, ancestor) -> Boolean
判断 element 是否是参数 ancestor 指定元素的后代节点。
因为 Element.descendantOf 内部对 ancestor 应用了 $(),所以参数 ancestor 既可以是元素,也可以是元素的 ID。
样例
<div id="australopithecus">
<div id="homo-herectus">
<div id="homo-sapiens"></div>
</div>
</div>
$('homo-sapiens').descendantOf('australopithecus');
// -> true
$('homo-herectus').descendantOf('homo-sapiens');
// -> false
...
cleanWhitespace(element) -> HTMLElement
移除元素中所有仅包含空白的文本节点,返回移除空白文本节点后的元素。
译注:所谓空白文本节点,是根据 XML 中的概念得来的,例如,有以下 HTML 代码:
<div>
<p>第一段</p>
</div>
<div> 的子节点(element.childNodes)包括 <p> 和空白文本节点(对于空白文本节点,各种浏览器的处理方式不一样), 这些空白文本节点有时对处理节点的顺序关系会造成影响,如上述 HTML 代码中我们通常认为 <p> 没有前导和后继兄弟节点, 但因为空白文本节点的干扰,程序可能会认为 <p> 有一个前导兄弟节点和一个后继兄弟节点。为消除这些干...
ancestors(element) -> [HTMLElement...]
返回 element 的所有先代节点(父节点、父节点的父节点...一直到最顶层节点),结果为一个数组,数组元素已经过 扩展。
返回数组的第一个元素是 element 的直接先代节点(即 parentNode),第二个元素是它的祖父节点, 依此类推,直到 html 元素。html 总是数组的最后一个成员,除非你显式查找它的先代节点。 但是你不愿意这么做,不是吗?
注意:所有 Prototype 的 DOM 扩展方法均忽略文本节点,仅返回元素节点。
样例
<html>
[…]
<body>
<div id="father">
<div id="kid"> </div>
</div>
</bo...