﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-看似花非花,雾非雾-文章分类-PROTOTYPE</title><link>http://www.blogjava.net/hummer008/category/31799.html</link><description>不走寻常路,要走就走无间道</description><language>zh-cn</language><lastBuildDate>Fri, 30 May 2008 15:53:19 GMT</lastBuildDate><pubDate>Fri, 30 May 2008 15:53:19 GMT</pubDate><ttl>60</ttl><item><title>prototype源码分析(转4) </title><link>http://www.blogjava.net/hummer008/articles/204074.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Fri, 30 May 2008 05:56:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/204074.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/204074.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/204074.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/204074.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/204074.html</trackback:ping><description><![CDATA[<div class="segment">
<h3>Function - 对Function类的扩展</h3>
<p class="description">Prototype对<span class="object">Function</span>对象的扩展比较简单, 但却是非常重要且非常有用的扩展。扩展主要包括2个方法, 他们被加到了<span class="method">Function.prototype</span>中, 这样就使得任意的函数对象都具备了这两个方法。 这两个方法的主要用途在于将某个函数绑定到特定的函数之上去执行。 </p>
<h4>Knowledge Prepare - 知识准备</h4>
<h4>Source View - 源码解析</h4>
<pre class="code">Function.prototype.bind = function() {
var __method = this;  <span class="comment">// 这里的this表示<span class="method">bind</span>方法的调用者, 是一个函数对象</span>
var args = $A(arguments);  <span class="comment">// 这里的$A(arguments)表示传入到<span class="method">bind</span>方法的参数, 不要与下面的$A(arguments)混淆</span>
var object = args.shift(); <span class="comment">// 调用<span class="method">args.shift()</span>方法返回第一个参数, 即目标对象; 此时args为除去第一个参数的一个参数数组</span>
return function() {  <span class="comment">// 不带有任何的参数的函数, 注意函数内部的$A(arguments)的含义</span>
<span class="comment">// 调用函数的apply方法执行函数, 其中的object为目标对象, args为<span class="method">bind</span>方法中的参数列表(除了第一个参数以外的参数构成的数组)</span>
return __method.apply(object, args.concat($A(arguments)));<span class="comment">// 事实上, 这里的$A(arguments)一定是一个空数组</span>
}
}
Function.prototype.bindAsEventListener = function(object) {
var __method = this;  <span class="comment">// 这里的this表示<span class="method">bind</span>方法的调用者, 是一个函数对象</span>
return function(event) {  <span class="comment">// 带有一个全局event参数的函数</span>
<span class="comment">// 调用函数的call方法执行函数, 其中的object为目标对象, 全局的event对象作为参数</span>
return __method.call(object, event || window.event);
}
}
</pre>
<h4>Field &amp; Function Reference - 属性方法一览</h4>
<h5>Function ( 实例 ) - 扩展</h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>bind(object[, arg1, arg2...])</td>
            <td>方法</td>
            <td>object：目标对象, 函数将绑定到该对象上去执行<br />
            argument list: 以参数列表的方式传入, 函数执行时所带的参数</td>
            <td>一个实例方法, 其调用者是一个函数对象, 表示将某个对象绑定到该函数上去执行, 其中的第一个参数表示目标对象, 其他参数将作为函数执行时的参数传入</td>
        </tr>
        <tr>
            <td>bindAsEventListener(object)</td>
            <td>方法</td>
            <td>object：目标对象</td>
            <td>一个实例方法, 其调用者是一个函数对象, 表示将某个对象绑定到该函数上去执行, 参数为目标对象, 在函数执行时将全局的Event对象作为参数传入</td>
        </tr>
    </tbody>
</table>
<h4>Analysis &amp; Usage - 分析与使用</h4>
</div>
<img src ="http://www.blogjava.net/hummer008/aggbug/204074.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-30 13:56 <a href="http://www.blogjava.net/hummer008/articles/204074.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype源码分析(转3) </title><link>http://www.blogjava.net/hummer008/articles/204073.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Fri, 30 May 2008 05:53:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/204073.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/204073.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/204073.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/204073.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/204073.html</trackback:ping><description><![CDATA[<div class="segment">
<h3>Object - 对Object类的扩展</h3>
<p class="description">Prototype对<span class="object">Object</span>类进行的扩展主要通过一个静态函数<span class="method">Object.extend(destination, source)</span>实现了JavaScript中的继承。 从语义的角度, <span class="method">Object.extend(destination, source)</span>方法有些不和逻辑, 因为它事实上仅仅实现了从源对象到目标对象的全息拷贝。不过你也可以这样认为：由于目标对象拥有了所有源对象所拥有的特性, 所以看上去就像目标对象继承了源对象(并加以扩展)一样。另外, Prototype对<span class="object">Object</span>扩展了几个比较有用的静态方法, 所有其他的类可以通过调用这些静态方法获取支持。 </p>
<h4>Source View - 源码解析</h4>
<pre class="code">Object.extend = function(destination, source) {  <span class="comment">// 一个静态方法表示继承, 目标对象将拥有源对象的所有属性和方法</span>
for (var property in source) {
destination[property] = source[property];   <span class="comment">// 利用动态语言的特性, 通过赋值动态添加属性与方法</span>
}
return destination;   <span class="comment">// 返回扩展后的对象</span>
}
Object.extend(Object, {
inspect: function(object) {   <span class="comment">// 一个静态方法, 传入一个对象, 返回对象的字符串表示</span>
try {
if (object == undefined) return 'undefined';  <span class="comment">// 处理undefined情况</span>
if (object == null) return 'null';     <span class="comment">// 处理null情况</span>
<span class="comment">// 如果对象定义了inspect方法, 则调用该方法返回, 否则返回对象的toString()值</span>
return object.inspect ? object.inspect() : object.toString();
} catch (e) {
if (e instanceof RangeError) return '...';  <span class="comment">// 处理异常情况</span>
throw e;
}
},
keys: function(object) {     <span class="comment">// 一个静态方法, 传入一个对象, 返回该对象中所有的属性, 构成数组返回</span>
var keys = [];
for (var property in object)
keys.push(property);     <span class="comment">// 将每个属性压入到一个数组中</span>
return keys;
},
values: function(object) {   <span class="comment">// 一个静态方法, 传入一个对象, 返回该对象中所有属性所对应的值, 构成数组返回</span>
var values = [];
for (var property in object)
values.push(object[property]);   <span class="comment">// 将每个属性的值压入到一个数组中</span>
return values;
},
clone: function(object) {    <span class="comment">// 一个静态方法, 传入一个对象, 克隆一个新对象并返回</span>
return Object.extend({}, object);
}
});
</pre>
<h4>Field &amp; Function Reference - 属性方法一览</h4>
<h5>Object ( 静态 ) - 扩展</h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>extend(destination, source)</td>
            <td>静态方法</td>
            <td>任意对象</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>inspect(object)</td>
            <td>静态方法</td>
            <td>任意对象</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>keys(object)</td>
            <td>静态方法</td>
            <td>任意对象</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>values(object)</td>
            <td>静态方法</td>
            <td>任意对象</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>clone(object)</td>
            <td>静态方法</td>
            <td>任意对象</td>
            <td>&nbsp;</td>
        </tr>
    </tbody>
</table>
<h4>Analysis &amp; Usage - 分析与使用</h4>
<p class="description"><span class="method">Object.extend(destination, source)</span>是Prototype实现的一个静态方法, 在JavaScript中模拟了继承。 事实上, 这个方法的语义更加倾向于：动态地为某个对象添加属性或方法。这个函数贯穿了整个Prototype的框架, 虽然核心思想是一致的, 但是在使用中还是能够看到一些不同之处, 这些不同之处很微小但是却值得一提。 </p>
<p class="description">1. 扩展现有对象的功能 - 为他们添加新的函数 </p>
<pre class="code">Object.extend(Number.prototype, {
toColorPart: function() {
var digits = this.toString(16);
if (this &lt; 16) return '0' + digits;
return digits;
},
......
});
</pre>
<p class="description">这是非常典型的对<span class="object">Number</span>类的扩展, 为<span class="object">Number.prototype</span>加入了一些额外的函数, 从而每个Number对象的实例都拥有这些方法。 </p>
<p class="description">2. 定义并实现抽象类 </p>
<pre class="code">var Enumerable = {
each: function(iterator) {
var index = 0;
try {
this._each(function(value) {
try {
iterator(value, index++);
} catch (e) {
if (e != $continue) throw e;
}
});
} catch (e) {
if (e != $break) throw e;
}
},
......
}
Object.extend(Array.prototype, Enumerable);
Object.extend(Array.prototype, {
_each: function(iterator) {
for (var i = 0; i &lt; this.length; i++)
iterator(this[i]);
},
......
}
</pre>
<p class="description">这是Prototype中的代码段, 它向我们展示了定义并实现抽象类的完整过程。这里首先定义了一个<span class="object">Enumerable</span>类, 这是一个抽象类。这个抽象类的内部, 有一个<span class="method">_each</span>方法被调用来完成一些逻辑。但是在整个<span class="object">Enumerable</span>的范围内, 你无法找到<span class="method">_each</span>方法的具体实现。也就是说, <span class="object">Enumerable</span>是一个抽象类, 具有一个<span class="method">_each</span>的抽象函数。 所以, 如果你还没有实现<span class="method">_each</span>这个抽象函数, 你是无法直接使用<span class="object">Enumerable</span>类的。之后的代码就比较明朗了, 使用<span class="method">Object.extend</span>方法, 将所有<span class="object">Enumerable</span>的函数复制给<span class="object">Array.prototype</span>, 然后在<span class="object">Array.prototype</span>中实现<span class="method">_each</span>方法, 这样就使得<span class="object">Array</span>对象具备了<span class="object">Enumerable</span>这个抽象类的所有特性。 </p>
</div>
<img src ="http://www.blogjava.net/hummer008/aggbug/204073.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-30 13:53 <a href="http://www.blogjava.net/hummer008/articles/204073.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype源码分析(转2)</title><link>http://www.blogjava.net/hummer008/articles/204072.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Fri, 30 May 2008 05:52:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/204072.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/204072.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/204072.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/204072.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/204072.html</trackback:ping><description><![CDATA[<div class="segment" style="width: 950px">
<h3>Class - 类创建</h3>
<p class="description"><span class="object">Class</span>类实现了在JavaScript中声明一个新的类, 并通过构造函数实例化这个类的机制。通过使用<span class="method">Class.create()</span>方法, 你实际上声明了一个新的类, 并定义了一个<span class="method">initialize()</span>方法作为构造函数, 一旦你在这个声明的类的prototype中实现了改该方法, 你就可以使用<span class="Object">new</span>操作符来创建并实例化一个类。 </p>
<h4>Knowledge Prepare - 知识准备</h4>
<p class="description">在JavaScript中, 当你定义了一个新的函数, 你实际上声明了一个新的类, 而这个函数本身就相当于类的构造函数。 下面的代码向你展示了两种不同的方式来创建一个新的<span class="object">Person</span>类, 而<span class="method">Person.prototype</span>的定义也紧跟在函数定义之后。 </p>
<pre class="code">var Person = function(name) {  <span class="comment">// 一个匿名函数, 并将这个函数赋值给一个<span class="object">Person</span>变量, 此时<span class="object">Person</span>成为一个类</span>
this.name = name;
}
function Person(name) {  <span class="comment">// 直接定义一个叫做<span class="object">Person</span>的函数表示<span class="object">Person</span>类</span>
this.name = name;
}
Person.prototype = {  <span class="comment">// 定义<span class="object">Person</span>的prototype域</span>
printName: function() {   <span class="comment">// 定义一个print函数</span>
alert(this.name);
}
}
</pre>
<p class="description">当你通过函数的方式声明了一个类之后, 你就可以通过<span class="method">new</span>操作符来实例化这个类。这样, 你就可以调用类的成员函数来完成你的逻辑。 </p>
<pre class="code">var person = new Person("Joe Smith"); <span class="comment">// 使用<span class="method">new</span>操作符来新建一个<span class="Object">Person</span>的实例, 并赋给变量<span class="method">person</span></span>
person.printName(); <span class="comment">// <span class="method">person</span>就可以看作是一个实例的引用(reference), 所以可以通过这个引用来调用<span class="Object">Person</span>类中的成员函数</span>
</pre>
<p class="description">我们来总结一下创建一个新的类的实例的整个流程和步骤： </p>
<p class="description">1. 通过定义一个函数的方式(匿名或者实名)来声明一个新的类. <br />
2. 如果有必要, 定义这个新的类的prototype域. <br />
3. 使用<span class="method">new</span>操作符紧跟你所定义的函数来创建一个新的类的实例. 一旦JavaScript编译器碰到了<span class="method">new</span>操作符, 它实际上创建了一个空的类实例变量.<br />
4. 将所有这个类的prototype域中的属性与方法复制到这个新的实例中, 并将其成员函数中所有的<span class="method">this</span>指针指向这个新创建的实例. <br />
5. 接下来, 执行紧跟在<span class="method">new</span>操作符后面的那个函数. <br />
6. 当你执行这个函数时, 如果你试图对一个不存在的属性进行赋值, JavaScript编译器将自动为你在这个实例范围内新创建这个属性. <br />
7. 函数执行完毕后, 将这个初始化完成的实例返回. </p>
<p class="description">在Prototype中, 使用<span class="object">Class</span>对象, 你可以以一个比较简单的方式来声明一个新的对象。通过使用<span class="method">Class.create()</span>, prototype为你创建了一个默认的构造函数initialize(), 一旦你实现这一函数, 就可以以一个类似Java中构造函数的方式来创建一个新的类的实例。 </p>
<h4>Source View - 源码解析</h4>
<pre class="code">var Class = {  <span class="comment">// 全局静态类, 用于声明一个新的类并提供构造函数支持</span>
create: function() {
return function() { <span class="comment">// 返回一个函数, 代表着这个新声明的类的构造函数</span>
<span class="comment">// 一个命名为<span class="method">initialize</span>的函数将被这个类实现作为类的构造函数</span>
this.initialize.apply(this, arguments);<span class="comment">// <span class="method">initialize</span>函数将在你实例化一个变量的时候被调用执行(即上面7个步骤中的第5步)</span>
}
}
}
</pre>
<h4>Field &amp; Function Reference - 属性方法一览</h4>
<h5>Class ( 静态 ) </h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>create()</td>
            <td>静态方法</td>
            <td>&nbsp;/</td>
            <td>用于声明一个新的类并提供了一个名为initialize构造函数支持</td>
        </tr>
    </tbody>
</table>
<h4>Analysis &amp; Usage - 分析与使用</h4>
<p class="description">通过<span class="object">Class</span>类, 你可以很容易地使用构造函数的方式创建一个新的类, 这对于Java程序员来说或许更加容易被接受。下面我们列出了Java和JavaScript各自声明和创建一个新的类的代码对比, 我们可以看到, 他们是如此相似： </p>
<pre class="code">var Person = Class.create(); <span class="comment">// 类的声明</span>              |public class Person { <span class="comment">// 类的声明</span>
Person.prototype = {                                 |    private String name;
initialize: function(name) {  <span class="comment">// 构造函数</span>          |    public Person(String name){ <span class="comment">// 构造函数</span>
this.name = name;                               |       this.name = name;
}                                                 |    }
printName: function() {  <span class="comment">// 成员函数</span>               |    public void printName(){  <span class="comment">// 成员函数</span>
alert(this.name);                               |       System.out.println(name);
}                                                 |    }
}                                                    |}
var person = new Person("Joe Smith");<span class="comment">// 创建实例</span>      |Person person = new Person("Joe Smith");<span class="comment">// 创建实例</span>
person.printName(); <span class="comment">// 函数调用</span>                       |person.printName(); <span class="comment">// 函数调用</span>
</pre>
</div>
<img src ="http://www.blogjava.net/hummer008/aggbug/204072.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-30 13:52 <a href="http://www.blogjava.net/hummer008/articles/204072.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype源码分析(转1)</title><link>http://www.blogjava.net/hummer008/articles/204071.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Fri, 30 May 2008 05:51:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/204071.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/204071.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/204071.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/204071.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/204071.html</trackback:ping><description><![CDATA[<div class="segment" style="width: 950px">
<h3>Basic - 基础代码</h3>
<p class="description">在开始所有的<span class="Object">Prototype</span>学习之旅之前，我们首先对<span class="Object">Prototype</span>中最常用的一些公用函数做一些研究，这些JavaScript函数将贯穿整个<span class="Object">Prototype</span>框架，熟练使用它们不仅有助于我们学习<span class="Object">Prototype</span>框架，同时也为我们自己编写JavaScript应用提供了独特的思路。 </p>
<h4>Source View - 源码解析</h4>
<pre class="code">var Prototype = {     <span class="comment">// 定义一个<span class="Object">Prototype</span>对象，封装了一些简单的静态函数和变量</span>
Version: '1.5.0_rc1',     <span class="comment">// 定义当前<span class="Object">Prototype</span>框架的版本号</span>
ScriptFragment: '(?:
<script.*?>)((\n|\r|.)*?)(?:&lt;\/script&gt;)',   <span class="comment">// 返回一个正则表达式，判断是否为Script块</span>
emptyFunction: function() {},    <span class="comment">// 返回一个空的函数, 该函数什么都不做, 在编写一些复杂流程中会使用此功能</span>
K: function(x) {return x}     <span class="comment">// 返回参数本身, 在编写一些复杂流程中会使用此功能</span>
}
<span class="comment">/*****************************************************************************************************************/</span>
function $() {   <span class="comment">// 一个根据id读取对象的快捷函数, 根据id返回所对应的对象</span>
var results = [], element;
for (var i = 0; i &lt; arguments.length; i++) { <span class="comment">// 可以接受多个参数, 返回由每个id所对应的对象构成的数组</span>
element = arguments[i];
if (typeof element == 'string')    <span class="comment">// 可以接受非string参数，直接返回对象本身</span>
element = document.getElementById(element);  <span class="comment">// 通过DOM操作读取对象</span>
results.push(Element.extend(element)); <span class="comment">// 参见<span class="method">Element.extend</span>的解析, 为返回的对象添加了一些额外特性，并压入到结果数组中</span>
}
return results.reduce(); <span class="comment">// 根据参数的个数返回对象或者对象数组</span>
}
<span class="comment">/*****************************************************************************************************************/</span>
var Abstract = new Object();  <span class="comment">// 定义了一个全局的对象, 可以理解为一个命名空间, 成为一个抽象基类</span>
<span class="comment">/*****************************************************************************************************************/</span>
var Try = {
these: function() {  <span class="comment">// 一个静态的函数, 接受多个函数作为参数, 依次执行并返回第一个成功执行的函数的结果</span>
var returnValue;
for (var i = 0; i &lt; arguments.length; i++) {
var lambda = arguments[i];   <span class="comment">// 每个参数都是一个将被执行的函数</span>
try {
returnValue = lambda();    <span class="comment">// 执行函数并记录返回值</span>
break;                     <span class="comment">// 第一次成功执行后, 即退出</span>
} catch (e) {}   <span class="comment">// 捕获每个函数执行过程中的异常</span>
}
return returnValue;
}
}
<span class="comment">/*****************************************************************************************************************/</span>
var PeriodicalExecuter = Class.create();  <span class="comment">// 定义一个定时器, 重复执行某一函数</span>
PeriodicalExecuter.prototype = {
initialize: function(callback, frequency) {  <span class="comment">// 构造函数, 定义需要重复执行的函数和执行周期</span>
this.callback = callback;      <span class="comment">// 需要重复执行的函数</span>
this.frequency = frequency;    <span class="comment">// 重复执行的周期, 单位是秒</span>
this.currentlyExecuting = false;   <span class="comment">// 是否当前执行标志</span>
this.registerCallback();    <span class="comment">// 调用重复执行的函数</span>
},
registerCallback: function() { <span class="comment">// 调用<span class="method">window.setInterval</span>函数完成重复执行, 返回一个标志留作被<span class="method">stop</span>函数调用, 以停止定时器</span>
<span class="comment">// 第一个参数巧妙地使用了<span class="method">bind</span>方法, 将<span class="Object">this</span>作为<span class="method">bind</span>的参数, 这样<span class="method">onTimeEvent</span>方法内部可以通过<span class="Object">this</span>获取当前对象的引用</span>
this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
},
stop: function() {
if (!this.timer) return;   <span class="comment">// 通过<span class="method">setInterval</span>函数的返回值来判断是否当前执行</span>
clearInterval(this.timer);   <span class="comment">// 当前执行时, 调用<span class="method">clearInterval</span>方法来中止当前的执行</span>
this.timer = null;    <span class="comment">// 将当前执行的标志设置为<span class="Object">null</span></span>
},
onTimerEvent: function() {
if (!this.currentlyExecuting) {  <span class="comment">// 判断是否当前执行, 否则跳过, 相当于一个同步信号量</span>
try {
this.currentlyExecuting = true;  <span class="comment">// 设置是否当前执行的标志</span>
this.callback(this);   <span class="comment">// 调用<span class="method">callback</span>完成真正的函数执行</span>
} finally {
this.currentlyExecuting = false;  <span class="comment">// 无论是否成功执行, 最终设置当前执行标志为<span class="Object">false</span></span>
}
}
}
}
</pre>
<h4>Field &amp; Function Reference - 属性方法一览</h4>
<h5>Prototype ( 静态 ) </h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>Version</td>
            <td>静态属性</td>
            <td>&nbsp;/</td>
            <td>表示Prototype框架的版本号</td>
        </tr>
        <tr>
            <td>ScriptFragment</td>
            <td>静态属性</td>
            <td>&nbsp;/</td>
            <td>表示script代码段的正则表达式</td>
        </tr>
        <tr>
            <td>emptyFunction</td>
            <td>静态方法</td>
            <td>&nbsp;/</td>
            <td>返回一个什么都不做的空函数</td>
        </tr>
        <tr>
            <td>K</td>
            <td>静态方法</td>
            <td>任意对象</td>
            <td>返回传入的参数</td>
        </tr>
    </tbody>
</table>
<h5>$() ( 静态 ) </h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>$()</td>
            <td>静态方法</td>
            <td>string或者任意对象, 参数数量不限</td>
            <td>根据参数的类型和数量返回DOM操作的结果, 传入的参数为string时，返回document.getElementById所读取的对象; 传入的参数为非string类型的对象时, 直接返回参数本身; 当参数个数是1个时, 直接返回上述操作所得的结果; 当参数个数大于1个时, 将每个参数操作的结果组成一个对象数组返回</td>
        </tr>
    </tbody>
</table>
<h5>Abstract ( 静态 ) </h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>Abstract</td>
            <td>类</td>
            <td>&nbsp;/</td>
            <td>一个全局的对象, 可以理解为一个命名空间, 成为一个抽象基类</td>
        </tr>
    </tbody>
</table>
<h5>Try ( 静态 )</h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>these</td>
            <td>静态方法</td>
            <td>多个有待依次执行的函数</td>
            <td>返回第一个成功执行的函数的执行结果</td>
        </tr>
    </tbody>
</table>
<h5>PeriodicalExecuter ( 实例 )</h5>
<table class="reference" cellspacing="0" cellpadding="0">
    <tbody>
        <tr>
            <th width="20%">Method / Property</th>
            <th width="15%">Kind</th>
            <th width="20%">Arguments</th>
            <th width="45%">Description</th>
        </tr>
        <tr>
            <td>callback</td>
            <td>属性</td>
            <td>&nbsp;/</td>
            <td>构造函数实例化时初始化的属性, 定义定时器重复执行时真正需要调用的函数</td>
        </tr>
        <tr>
            <td>frequency</td>
            <td>属性(Number)</td>
            <td>&nbsp;/</td>
            <td>构造函数实例化时初始化的属性, 定义定时器重复执行的时间间隔</td>
        </tr>
        <tr>
            <td>currentlyExecuting</td>
            <td>属性(Boolean)</td>
            <td>&nbsp;/</td>
            <td>在整个定时器执行过程中表示是否当前执行的标志, 可以作为执行过程中的同步信号量</td>
        </tr>
        <tr>
            <td>timer</td>
            <td>属性</td>
            <td>&nbsp;/</td>
            <td>一个内部变量, 在registerCallback方法调用window.setInterval时记录该函数的返回值, 用以给stop方法使用</td>
        </tr>
        <tr>
            <td>registerCallback</td>
            <td>方法</td>
            <td>&nbsp;/</td>
            <td>在构造函数初始化完成时调用执行, 也可以直接调用该函数启动定时器, 在函数内部通过调用window.setInterval方法完成定时器功能</td>
        </tr>
        <tr>
            <td>stop</td>
            <td>方法</td>
            <td>this.timer, 即重复执行时调用setInterval的返回值</td>
            <td>用于暂停定时器, 通过实例变量调用完成</td>
        </tr>
        <tr>
            <td>onTimerEvent</td>
            <td>方法</td>
            <td>&nbsp;/</td>
            <td>一个内部方法, 真正调用callback完成函数执行</td>
        </tr>
    </tbody>
</table>
<h4>Analysis &amp; Usage - 分析与使用</h4>
<h4>Extension - 扩展</h4>
<p class="description">$()为我们提供了一个快捷的方式，通过id来读取一个对象，从而避免了我们在编写JavaScript代码时的重复而又冗长的代码段。然而，在某些情况下，我们需要通过对象的name属性来读取对象，并对对象进行一定的操作，此时，$()方法就显得有些力不从心了。因而在这里，我针对这种需求，并模仿$()方法，实现了一个通过name来读取对象的函数。 </p>
<pre class="code"></pre>
<p class="description">事实上，getElementsByName()已经帮我们解决了大多数的问题。由于name在HTML的document中可以不唯一，因而我们需要对此进行简单的处理，当name唯一时，直接返回单一对象；当name不唯一时，返回一个数组(这已经与getElementsByName()本身的含义不同了，当然这仅仅是为了方便编程而已)。 </p>
</div>
<img src ="http://www.blogjava.net/hummer008/aggbug/204071.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-30 13:51 <a href="http://www.blogjava.net/hummer008/articles/204071.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype源码分析连接</title><link>http://www.blogjava.net/hummer008/articles/204070.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Fri, 30 May 2008 05:48:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/204070.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/204070.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/204070.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/204070.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/204070.html</trackback:ping><description><![CDATA[http://www.demo2do.com/prototype/reference/zh-cn/Base.htm <br />
<br />
http://p-x1984.javaeye.com/blog/196906
<img src ="http://www.blogjava.net/hummer008/aggbug/204070.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-30 13:48 <a href="http://www.blogjava.net/hummer008/articles/204070.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype.js开发笔记(转)</title><link>http://www.blogjava.net/hummer008/articles/203722.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:55:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203722.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203722.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203722.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203722.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203722.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Table of Contents1. Programming Guide1.1. Prototype是什么?1.2. 关联文章1.3. 通用性方法1.3.1. 使用 $()方法1.3.2. 使用$F()方法1.3.3. 使用$A()方法1.3.4. 使用$H()方法1.3.5. 使用$R()方法1.3.6. 使用Try.these()方...&nbsp;&nbsp;<a href='http://www.blogjava.net/hummer008/articles/203722.html'>阅读全文</a><img src ="http://www.blogjava.net/hummer008/aggbug/203722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:55 <a href="http://www.blogjava.net/hummer008/articles/203722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype.js的学习资料(转)</title><link>http://www.blogjava.net/hummer008/articles/203716.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:48:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203716.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203716.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203716.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203716.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203716.html</trackback:ping><description><![CDATA[<p>1.prototype.js的官方网站<br />
<a href="http://ajaxian.com/resources/" target="_blank">http://www.prototypejs.org/</a></p>
<p>2.prototype.js 官方api文档<br />
<a href="http://prototypejs.org/api/" target="_blank">http://prototypejs.org/api/</a></p>
<p>3.开始学习prototype.js<br />
<a href="http://www.prototypejs.org/learn" target="_blank">http://www.prototypejs.org/learn</a></p>
<p>4.prototype.js sample<br />
<a href="http://prototype-window.xilinus.com/samples.html" target="_blank">http://prototype-window.xilinus.com/samples.html</a></p>
<p>5.prototype.js讨论板<br />
<a href="http://groups.google.com/group/Prototypejs/topics" target="_blank">http://groups.google.com/group/Prototypejs/topics</a></p>
<p>6.precipitant的学习笔记，貌似看到一，并没有找到二？^_^<br />
<a href="http://blog.csdn.net/precipitant/archive/2007/10/13/1823220.aspx" target="_blank">http://blog.csdn.net/precipitant/archive/2007/10/13/1823220.aspx</a></p>
<p>7.phphot写的prototype.js教程<br />
<a href="http://blog.csdn.net/phphot/archive/2007/10/10/1818938.aspx" target="_blank">http://blog.csdn.net/phphot/archive/2007/10/10/1818938.aspx</a></p>
<p>8.一个ajax的讨论论坛<br />
<a href="http://bbs.okajax.com/forum-13-1.html" target="_blank">http://bbs.okajax.com/forum-13-1.html</a></p>
<p>9.prototype.js开发应用手册<br />
<a href="http://bbs.blueidea.com/thread-2812502-1-1.html">http://bbs.blueidea.com/thread-2812502-1-1.html</a></p>
<p>10.一个ajax框架介绍的网站<br />
<a href="http://ajaxian.com/resources/">http://ajaxian.com/resources/</a></p>
<p>11.以下几个网站也是学习prototype.js的不错的网站,含有prototype.js中文教程<br />
<a href="https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html" target="_blank">https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html</a><br />
<a href="http://www.lvjiyong.com/item/jquery-with-prototype-using-ajax" target="_blank">http://www.lvjiyong.com/item/jquery-with-prototype-using-ajax</a><br />
<a href="http://591wap.cn/works/prototype/using_ajax_request.html" target="_blank">http://591wap.cn/works/prototype/using_ajax_request.html</a></p>
<p>12.JAVA.NET上的prototype.js学习笔记<br />
<a href="https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html">https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html</a></p>
<p>13.prototype.js源文件以及中英文手册下载,请移步这里<br />
<strong><a href="http://www.dayanmei.com/blog.php/ID_796.htm">prototype.js教程及prototype中文手册</a></strong></p>
 <img src ="http://www.blogjava.net/hummer008/aggbug/203716.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:48 <a href="http://www.blogjava.net/hummer008/articles/203716.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Prototype（1.5 rc2)使用指南（五）(转)</title><link>http://www.blogjava.net/hummer008/articles/203713.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:42:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203713.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203713.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203713.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203713.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203713.html</trackback:ping><description><![CDATA[<div>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">十三</span>).Prototype1.5 rc2<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">版指南最后一篇之</span>Position</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Position</font><span style="font-family: 宋体">是</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">中定义的一个对象，提供了操作</span><font face="Times New Roman">DOM</font><span style="font-family: 宋体">中与位置相关的方法，要很好的理解元素在页面中的位置，可以参考这篇文章：</span><a href="http://www.autisticcuckoo.net/archive.php?id=2004/12/07/relatively-absolute" target="_blank"><font face="Times New Roman" color="#666666">Relatively Absolute</font></a></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">具体代码如下，按照代码说说，其中英文是作者的注释，中文红色的才是偶的说明或翻译英文的注释，采用顶式注释法</span><font face="Times New Roman">(</font><span style="font-family: 宋体">注释在要说明的代码的上面</span><font face="Times New Roman">)</font><span style="font-family: 宋体">说明</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">&nbsp; // set to true if needed, warning: firefox performance problems<br />
&nbsp; // NOT neeeded for page scrolling, only if draggable contained in<br />
&nbsp; // scrollable elements<br />
&nbsp; //</font><span style="font-family: 宋体">只有在使用拖动的时候元素包含在有滚动条的元素中才需要设置为</span></font><font face="Times New Roman" size="3">true<br />
&nbsp; includeScrollOffsets: false, </font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">&nbsp; // must be called before calling withinIncludingScrolloffset, every time the<br />
&nbsp; // page is scrolled<br />
&nbsp; //</font><span style="font-family: 宋体">当页面被</span><font face="Times New Roman">scrolled</font><span style="font-family: 宋体">后，使用</span><font face="Times New Roman">withinIncludingScrolloffset</font><span style="font-family: 宋体">的时候需要先调用这个方法</span></font><br />
<font face="Times New Roman" size="3">&nbsp; prepare: function() {<br />
&nbsp;&nbsp;&nbsp; //</font><span style="font-family: 宋体"><font size="3">横向滚动条滚动的距离</font></span><br />
<font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; this.deltaX =&nbsp; window.pageXOffset <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || document.documentElement.scrollLeft <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || document.body.scrollLeft <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp; //</font><span style="font-family: 宋体"><font size="3">纵向滚动条滚动的距离</font></span><br />
<font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; this.deltaY =&nbsp; window.pageYOffset <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || document.documentElement.scrollTop <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || document.body.scrollTop <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; || 0;<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">元素由于滚动条偏移的总距离</span></font><font face="Times New Roman" size="3">&nbsp; <br />
realOffset: function(element) {<br />
&nbsp;&nbsp;&nbsp; var valueT = 0, valueL = 0;<br />
&nbsp;&nbsp;&nbsp; do {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueT += element.scrollTop&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueL += element.scrollLeft || 0; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element = element.parentNode;<br />
&nbsp;&nbsp;&nbsp; } while (element);<br />
&nbsp;&nbsp;&nbsp; return [valueL, valueT];<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">元素在页面中由</span><font face="Times New Roman">offsetParent</font><span style="font-family: 宋体">累积的</span><font face="Times New Roman">offset</font><span style="font-family: 宋体">，当</span><font face="Times New Roman">offsetParent</font><span style="font-family: 宋体">都没有滚动条时，就是元素在页面中的位置</span></font><br />
<font face="Times New Roman" size="3">cumulativeOffset: function(element) {<br />
&nbsp;&nbsp;&nbsp; var valueT = 0, valueL = 0;<br />
&nbsp;&nbsp;&nbsp; do {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueT += element.offsetTop&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueL += element.offsetLeft || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element = element.offsetParent;<br />
&nbsp;&nbsp;&nbsp; } while (element);<br />
&nbsp;&nbsp;&nbsp; return [valueL, valueT];<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">元素相对于</span><font face="Times New Roman">containing block("nearest positioned ancestor")</font><span style="font-family: 宋体">的位置，也就是相对于最近的一个</span><font face="Times New Roman">position</font><span style="font-family: 宋体">设置为</span><font face="Times New Roman">relative</font><span style="font-family: 宋体">或者</span><font face="Times New Roman">absolute</font><span style="font-family: 宋体">的祖先节点的位置，如果没有就是相对于</span><font face="Times New Roman"> body</font><span style="font-family: 宋体">的位置，跟</span><font face="Times New Roman">style.top</font><span style="font-family: 宋体">，</span><font face="Times New Roman">style.left</font><span style="font-family: 宋体">一样？</span></font><br />
<font face="Times New Roman" size="3">positionedOffset: function(element) {<br />
&nbsp;&nbsp;&nbsp; var valueT = 0, valueL = 0;<br />
&nbsp;&nbsp;&nbsp; do {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueT += element.offsetTop&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueL += element.offsetLeft || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element = element.offsetParent;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (element) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(element.tagName==&#8217;BODY&#8217;) break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var p = Element.getStyle(element, 'position&#8217;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (p == 'relative&#8217; || p == 'absolute&#8217;) break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; } while (element);<br />
&nbsp;&nbsp;&nbsp; return [valueL, valueT];<br />
&nbsp; },<br />
&nbsp;&nbsp;<br />
&nbsp; //offsetParent<br />
&nbsp; offsetParent: function(element) {<br />
&nbsp;&nbsp;&nbsp; if (element.offsetParent) return element.offsetParent;<br />
&nbsp;&nbsp;&nbsp; if (element == document.body) return element;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; while ((element = element.parentNode) &amp;&amp; element != document.body)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Element.getStyle(element, 'position&#8217;) != &#8217;static&#8217;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return element;</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">&nbsp;&nbsp;&nbsp; return document.body;<br />
&nbsp; },<br />
&nbsp; <br />
&nbsp; // caches x/y coordinate pair to use with overlap<br />
&nbsp; //</font><span style="font-family: 宋体">判断指定的位置是否在元素内</span></font><br />
<font face="Times New Roman" size="3">&nbsp; within: function(element, x, y) {<br />
&nbsp;&nbsp;&nbsp; if (this.includeScrollOffsets)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.withinIncludingScrolloffsets(element, x, y);<br />
&nbsp;&nbsp;&nbsp; this.xcomp = x;<br />
&nbsp;&nbsp;&nbsp; this.ycomp = y;<br />
&nbsp;&nbsp;&nbsp; this.offset = this.cumulativeOffset(element);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; return (y &gt;= this.offset[1] &amp;&amp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y &lt;&nbsp; this.offset[1] + element.offsetHeight &amp;&amp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x &gt;= this.offset[0] &amp;&amp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x &lt;&nbsp; this.offset[0] + element.offsetWidth);<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">跟</span><font face="Times New Roman">within</font><span style="font-family: 宋体">差不多，不过考虑到滚动条，也许是在元素上面，但不是直接在上面，因为滚动条也许已经使元素不可见了</span></font><font face="Times New Roman" size="3">&nbsp; <br />
withinIncludingScrolloffsets: function(element, x, y) {<br />
&nbsp;&nbsp;&nbsp; var offsetcache = this.realOffset(element);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; this.xcomp = x + offsetcache[0] - this.deltaX;<br />
&nbsp;&nbsp;&nbsp; this.ycomp = y + offsetcache[1] - this.deltaY;<br />
&nbsp;&nbsp;&nbsp; this.offset = this.cumulativeOffset(element);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; return (this.ycomp &gt;= this.offset[1] &amp;&amp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.ycomp &lt;&nbsp; this.offset[1] + element.offsetHeight &amp;&amp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.xcomp &gt;= this.offset[0] &amp;&amp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.xcomp &lt;&nbsp; this.offset[0] + element.offsetWidth);<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">&nbsp; // within must be called directly before<br />
&nbsp; //</font><span style="font-family: 宋体">在调用这个方法前，必须先调用</span><font face="Times New Roman">within</font><span style="font-family: 宋体">，返回在</span><font face="Times New Roman">with</font><span style="font-family: 宋体">指定的位置在水平或者垂直方向上占用的百分比</span></font><br />
<font face="Times New Roman" size="3">&nbsp; overlap: function(mode, element) {&nbsp; <br />
&nbsp;&nbsp;&nbsp; if (!mode) return 0;&nbsp; <br />
&nbsp;&nbsp;&nbsp; if (mode == 'vertical&#8217;) <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((this.offset[1] + element.offsetHeight) - this.ycomp) / <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.offsetHeight;<br />
&nbsp;&nbsp;&nbsp; if (mode == 'horizontal&#8217;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((this.offset[0] + element.offsetWidth) - this.xcomp) / <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.offsetWidth;<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">返回元素相对页面的真实位置</span></font><font face="Times New Roman" size="3">&nbsp; <br />
page: function(forElement) {<br />
&nbsp;&nbsp;&nbsp; var valueT = 0, valueL = 0;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; var element = forElement;<br />
&nbsp;&nbsp;&nbsp; do {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueT += element.offsetTop&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueL += element.offsetLeft || 0;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Safari fix<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (element.offsetParent==document.body)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Element.getStyle(element,&#8217;position&#8217;)==&#8217;absolute&#8217;) break;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; } while (element = element.offsetParent);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; element = forElement;<br />
&nbsp;&nbsp;&nbsp; do {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!window.opera || element.tagName==&#8217;BODY&#8217;) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueT -= element.scrollTop&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueL -= element.scrollLeft || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; } while (element = element.parentNode);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; return [valueL, valueT];<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">设置</span><font face="Times New Roman">target</font><span style="font-family: 宋体">为</span><font face="Times New Roman">source</font><span style="font-family: 宋体">的位置，大小</span></font><font face="Times New Roman" size="3">&nbsp; <br />
clone: function(source, target) {<br />
&nbsp;&nbsp;&nbsp; var options = Object.extend({<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setLeft:&nbsp;&nbsp;&nbsp; true,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setTop:&nbsp;&nbsp;&nbsp;&nbsp; true,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setWidth:&nbsp;&nbsp; true,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setHeight:&nbsp; true,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; offsetTop:&nbsp; 0,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; offsetLeft: 0<br />
&nbsp;&nbsp;&nbsp; }, arguments[2] || {})</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; // find page position of source<br />
&nbsp;&nbsp;&nbsp; source = $(source);<br />
&nbsp;&nbsp;&nbsp; var p = Position.page(source);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; // find coordinate system to use<br />
&nbsp;&nbsp;&nbsp; target = $(target);<br />
&nbsp;&nbsp;&nbsp; var delta = [0, 0];<br />
&nbsp;&nbsp;&nbsp; var parent = null;<br />
&nbsp;&nbsp;&nbsp; // delta [0,0] will do fine with position: fixed elements, <br />
&nbsp;&nbsp;&nbsp; // position:absolute needs offsetParent deltas<br />
&nbsp;&nbsp;&nbsp; if (Element.getStyle(target,&#8217;position&#8217;) == 'absolute&#8217;) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent = Position.offsetParent(target);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delta = Position.page(parent);<br />
&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; // correct by body offsets (fixes Safari)<br />
&nbsp;&nbsp;&nbsp; if (parent == document.body) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delta[0] -= document.body.offsetLeft;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delta[1] -= document.body.offsetTop; <br />
&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; // set position<br />
&nbsp;&nbsp;&nbsp; if(options.setLeft)&nbsp;&nbsp; target.style.left&nbsp; = (p[0] - delta[0] + options.offsetLeft) + 'px&#8217;;<br />
&nbsp;&nbsp;&nbsp; if(options.setTop)&nbsp;&nbsp;&nbsp; target.style.top&nbsp;&nbsp; = (p[1] - delta[1] + options.offsetTop) + 'px&#8217;;<br />
&nbsp;&nbsp;&nbsp; if(options.setWidth)&nbsp; target.style.width = source.offsetWidth + 'px&#8217;;<br />
&nbsp;&nbsp;&nbsp; if(options.setHeight) target.style.height = source.offsetHeight + 'px&#8217;;<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">将</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的</span><font face="Times New Roman">position</font><span style="font-family: 宋体">设置为</span><font face="Times New Roman">absolute</font><span style="font-family: 宋体">的模式</span></font><font face="Times New Roman" size="3">&nbsp; <br />
absolutize: function(element) {<br />
&nbsp;&nbsp;&nbsp; element = $(element);<br />
&nbsp;&nbsp;&nbsp; if (element.style.position == 'absolute&#8217;) return;<br />
&nbsp;&nbsp;&nbsp; Position.prepare();</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; var offsets = Position.positionedOffset(element);<br />
&nbsp;&nbsp;&nbsp; var top&nbsp;&nbsp;&nbsp;&nbsp; = offsets[1];<br />
&nbsp;&nbsp;&nbsp; var left&nbsp;&nbsp;&nbsp; = offsets[0];<br />
&nbsp;&nbsp;&nbsp; var width&nbsp;&nbsp; = element.clientWidth;<br />
&nbsp;&nbsp;&nbsp; var height&nbsp; = element.clientHeight;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; element._originalLeft&nbsp;&nbsp; = left - parseFloat(element.style.left&nbsp; || 0);<br />
&nbsp;&nbsp;&nbsp; element._originalTop&nbsp;&nbsp;&nbsp; = top&nbsp; - parseFloat(element.style.top || 0);<br />
&nbsp;&nbsp;&nbsp; element._originalWidth&nbsp; = element.style.width;<br />
&nbsp;&nbsp;&nbsp; element._originalHeight = element.style.height;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; element.style.position = 'absolute&#8217;;<br />
&nbsp;&nbsp;&nbsp; element.style.top&nbsp;&nbsp;&nbsp; = top + 'px&#8217;;;<br />
&nbsp;&nbsp;&nbsp; element.style.left&nbsp;&nbsp; = left + 'px&#8217;;;<br />
&nbsp;&nbsp;&nbsp; element.style.width&nbsp; = width + 'px&#8217;;;<br />
&nbsp;&nbsp;&nbsp; element.style.height = height + 'px&#8217;;;<br />
&nbsp; },</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">//</font><span style="font-family: 宋体">将</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的</span><font face="Times New Roman">position</font><span style="font-family: 宋体">设置为</span><font face="Times New Roman">absolute</font><span style="font-family: 宋体">的模式</span></font><font face="Times New Roman" size="3">&nbsp; <br />
relativize: function(element) {<br />
&nbsp;&nbsp;&nbsp; element = $(element);<br />
&nbsp;&nbsp;&nbsp; if (element.style.position == 'relative&#8217;) return;<br />
&nbsp;&nbsp;&nbsp; Position.prepare();</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; element.style.position = 'relative&#8217;;<br />
&nbsp;&nbsp;&nbsp; var top&nbsp; = parseFloat(element.style.top&nbsp; || 0) - (element._originalTop || 0);<br />
&nbsp;&nbsp;&nbsp; var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;&nbsp;&nbsp; element.style.top&nbsp;&nbsp;&nbsp; = top + 'px&#8217;;<br />
&nbsp;&nbsp;&nbsp; element.style.left&nbsp;&nbsp; = left + 'px&#8217;;<br />
&nbsp;&nbsp;&nbsp; element.style.height = element._originalHeight;<br />
&nbsp;&nbsp;&nbsp; element.style.width&nbsp; = element._originalWidth;<br />
&nbsp; }<br />
}</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">// Safari returns margins on body which is incorrect if the child is absolutely<br />
// positioned.&nbsp; For performance reasons, redefine Position.cumulativeOffset for<br />
// KHTML/WebKit only.<br />
if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) {<br />
&nbsp; Position.cumulativeOffset = function(element) {<br />
&nbsp;&nbsp;&nbsp; var valueT = 0, valueL = 0;<br />
&nbsp;&nbsp;&nbsp; do {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueT += element.offsetTop&nbsp; || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueL += element.offsetLeft || 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (element.offsetParent == document.body)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Element.getStyle(element, 'position&#8217;) == 'absolute&#8217;) break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element = element.offsetParent;<br />
&nbsp;&nbsp;&nbsp; } while (element);<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; return [valueL, valueT];<br />
&nbsp; }<br />
}</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">终于把</span><a href="http://prototype.conio.net/" target="_blank"><font face="Times New Roman" color="#666666">Prototype</font></a><span style="font-family: 宋体">的所有部分都写完了，哈哈，越来越佩服自己的耐力了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">下一步决定写写</span><a href="http://script.aculo.us/" target="_blank"><font face="Times New Roman" color="#666666">Scriptaculous</font></a><span style="font-family: 宋体">这个超级流行的效果库</span></font></p>
<p style="margin: 0cm 0cm 0pt"><a title="Permanent link to Prototype1.5的下载为什么不简单点" href="http://www.7tt.com.cn/perol/2007/01/20/prototype15%e7%9a%84%e4%b8%8b%e8%bd%bd%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%8d%e7%ae%80%e5%8d%95%e7%82%b9/"><font color="#666666"><font size="3"><font face="Times New Roman">Prototype1.5</font><span style="font-family: 宋体">的下载为什么不简单点</font></font></a></span></p>
<p style="margin: 0cm 0cm 0pt; text-align: left" align="left"><font size="3"><span style="font-family: 宋体">这几天在论坛和博客上看到很多人问</span><font face="Times New Roman">Prototype1.5</font><span style="font-family: 宋体">怎么下载，为什么下载这么困难呢？</span></font><br />
<font face="Times New Roman" size="3">Prototype</font><font size="3"><span style="font-family: 宋体">的官方网站是：</span><a href="http://prototype.conio.net/" target="_blank"><font face="Times New Roman" color="#666666">http://prototype.conio.net/</font></a><span style="font-family: 宋体">，如果你一下子找不到，到</span><font face="Times New Roman">google</font><span style="font-family: 宋体">上搜索</span><a href="http://www.google.com/search?hl=zh-CN&amp;newwindow=1&amp;rlz=1B3GGGL_zh-CNCN202CN202&amp;q=prototype&amp;btnG=%E6%90%9C%E7%B4%A2&amp;lr=" target="_blank"><font face="Times New Roman" color="#666666">Prototype</font></a><span style="font-family: 宋体">就找到了</span></font><br />
<font size="3"><span style="font-family: 宋体">下载当然要到官方网站下载了，但是问题是</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">官方网站更新太慢，首页上的下载连接还是</span><font face="Times New Roman">prototype1.4</font><span style="font-family: 宋体">的，而且只是一个单独的</span><font face="Times New Roman">js</font><span style="font-family: 宋体">文件</span></font><br />
<span style="font-family: 宋体"><font size="3">那么怎么下载最新版本的呢？</font></span><br />
<font face="Times New Roman" size="3">1</font><font size="3"><span style="font-family: 宋体">，如果你只想得到一个单独的</span><font face="Times New Roman">js</font><span style="font-family: 宋体">文件使用的话，其实官方网站提供了最新版</span><font face="Times New Roman">1.5</font><span style="font-family: 宋体">的下载</span><font face="Times New Roman">, </font><span style="font-family: 宋体">下面连接就是下载地址了</span></font><a href="http://dev.rubyonrails.org/browser/trunk/railties/html/javascripts/prototype.js?format=raw" target="_blank"><font face="Times New Roman" color="#666666" size="3">http://dev.rubyonrails.org/browser/trunk/railties/html/javascripts/prototype.js?format=raw</font></a><br />
<font face="Times New Roman" size="3">2</font><font size="3"><span style="font-family: 宋体">，如果你想得到详细的源文件以及测试代码，需要通过</span><font face="Times New Roman">svn</font><span style="font-family: 宋体">下载：使用下面的命令就可以了：</span></font><font size="3"><font face="Times New Roman">svn co http://dev.rubyonrails.org/svn/rails/spinoffs/prototype<br />
</font><span style="font-family: 宋体">如果你没有</span><font face="Times New Roman">svn</font><span style="font-family: 宋体">的话，我已经下载打包了传到</span><font face="Times New Roman">51js</font><span style="font-family: 宋体">论坛中，查看下面连接的帖子中有下载的：</span><a href="http://bbs.51js.com/viewthread.php?tid=65070&amp;highlight=prototype" target="_blank"><font face="Times New Roman" color="#666666">http://bbs.51js.com/viewthread.php?tid=65070&amp;highlight=prototype</font></a></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">想必很多</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">爱好者都一直在等待着</span><font face="Times New Roman">prototype1.5</font><span style="font-family: 宋体">的发布，虽然等待的时间很长，但是这一令人激动的一天终于到来了</span></font><br />
<a href="http://www.7tt.com.cn/perol/2007/01/20/prototype15%e7%9a%84%e4%b8%8b%e8%bd%bd%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%8d%e7%ae%80%e5%8d%95%e7%82%b9/"><span style="font-family: 宋体"><font color="#666666" size="3">因为网友提醒</font></a></span><font size="3"><span style="font-family: 宋体">，今天访问</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">网站，发现原来的网址已经自动跳转到新的网站去了，</span><span style="font-family: 宋体">作者使用了一个独立的域名</span></font><a href="http://www.prototypejs.org/" target="_blank"><font face="Times New Roman" color="#666666" size="3">http://www.prototypejs.org/ </font></a><br />
<font size="3"><span style="font-family: 宋体">刚才在</span><font face="Times New Roman">google</font><span style="font-family: 宋体">里搜索</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">，发现搜索结果中出现的已经是新网站了，</span><font face="Times New Roman">google</font><span style="font-family: 宋体">爬虫也蛮勤快的嘛</span></font><br />
<span style="font-family: 宋体"><font size="3">更让人高兴的是，一向被人诟病的文档问题这一版有了非常大的提高，可以说是有了质的飞跃，以前的版本基本上没有文档，要使用只有自己理解了，</font></span><br />
<font size="3"><span style="font-family: 宋体">现在在它的官方网站上有专门的</span><font face="Times New Roman">API</font><span style="font-family: 宋体">参考以及一些使用的例子，看来作者真正的关于这个问题来了，</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">爱好者应该高兴一把了哈哈，赶快到</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">官方网站下载了</span><font face="Times New Roman">Engoy</font><span style="font-family: 宋体">吧</span></font><font size="3"><span style="font-family: 宋体">如果感觉阅读英文是一种折磨的话，可以参考我以前写的</span><a href="http://www.7tt.com.cn/perol/2006/11/27/prototype_15-rc2/"><font color="#666666"><font face="Times New Roman">prototype 1.5</font><span style="font-family: 宋体">使用指南</font></a></span><span style="font-family: 宋体">系列文章</span><font face="Times New Roman">.</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">－－声明：该使用指南文章为转载，由于是来源于多次转载，未找到原出处。再次感谢作者与翻译人员。</font></p>
</div>
 <img src ="http://www.blogjava.net/hummer008/aggbug/203713.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:42 <a href="http://www.blogjava.net/hummer008/articles/203713.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Prototype（1.5 rc2)使用指南（四）(转)</title><link>http://www.blogjava.net/hummer008/articles/203711.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:41:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203711.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203711.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203711.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203711.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203711.html</trackback:ping><description><![CDATA[<div>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">十一</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>form</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">这一部分提供了很多与表单操作有关的功能，包括以下部分，当通过</span><font face="Times New Roman">$</font><span style="font-family: 宋体">方法返回元素时，可以直接通过</span><font face="Times New Roman">$(element).method()</font><span style="font-family: 宋体">调用：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Form</font><span style="font-family: 宋体">对象：提供了操作整个表单的一些方法</span></font><br />
<font face="Times New Roman" size="3">Form.Element</font><span style="font-family: 宋体"><font size="3">对象：提供了操作某个表单元素的方法</font></span><br />
<font face="Times New Roman" size="3">TimedObserver</font><font size="3"><span style="font-family: 宋体">类：周期性表单监视器，当表单元素值改变的时候执行一个回调函数，有</span><font face="Times New Roman">Form</font><span style="font-family: 宋体">和</span><font face="Times New Roman">Element</font><span style="font-family: 宋体">两种类型</span></font><br />
<font face="Times New Roman" size="3">EventObserver</font><font size="3"><span style="font-family: 宋体">类：利用事件来监视表单元素，当表单元素值改变的时候执行一个回调函数，有</span><font face="Times New Roman">Form</font><span style="font-family: 宋体">和</span><font face="Times New Roman">Element</font><span style="font-family: 宋体">两种类型</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Form</font><span style="font-family: 宋体">对象：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">reset(form)</font><span style="font-family: 宋体">：</span></font><font size="3"><font face="Times New Roman">form.reset()<br />
serializeElements(elements)</font><span style="font-family: 宋体">：将</span><font face="Times New Roman">elements</font><span style="font-family: 宋体">中的元素序列化，就是返回指定的所有元素的</span><font face="Times New Roman">queryString</font><span style="font-family: 宋体">的形式，便于在</span><font face="Times New Roman">xmlhttp</font><span style="font-family: 宋体">或其他地方使用</span></font><br />
<font face="Times New Roman" size="3">serialize(form)</font><span style="font-family: 宋体"><font size="3">：序列化整个表单</font></span><br />
<font face="Times New Roman" size="3">getElements(form)</font><span style="font-family: 宋体"><font size="3">：返回表单的所有可序列化元素</font></span><br />
<font face="Times New Roman" size="3">getInputs(form, typeName, name)</font><font size="3"><span style="font-family: 宋体">：返回所有符合</span><font face="Times New Roman">typeName</font><span style="font-family: 宋体">和</span><font face="Times New Roman">name</font><span style="font-family: 宋体">的</span><font face="Times New Roman">input</font><span style="font-family: 宋体">元素</span></font><br />
<font face="Times New Roman" size="3">disable(form)</font><span style="font-family: 宋体"><font size="3">：使整个表单处于不可用状态</font></span><br />
<font face="Times New Roman" size="3">enable(form) </font><span style="font-family: 宋体"><font size="3">：是整个表单可用</font></span><br />
<font face="Times New Roman" size="3">findFirstElement(form)</font><font size="3"><span style="font-family: 宋体">：返回类型为</span><font face="Times New Roman">'input&#8217;, &#8217;select&#8217;, 'textarea&#8217;</font><span style="font-family: 宋体">的第一个可用的非隐藏元素</span></font><br />
<font face="Times New Roman" size="3">focusFirstElement(form)</font><font size="3"><span style="font-family: 宋体">：使</span><font face="Times New Roman">findFirstElement(form)</font><span style="font-family: 宋体">返回的元素得到焦点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Form.Element</font><span style="font-family: 宋体">对象：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">focus(element) select(element)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">html</font><span style="font-family: 宋体">元素内置方法的封装，除了返回元素本身</span></font><br />
<font face="Times New Roman" size="3">serialize(element)</font><font size="3"><span style="font-family: 宋体">：序列化指定的表单元素，返回</span><font face="Times New Roman">key=value</font><span style="font-family: 宋体">的形式，返回的</span><font face="Times New Roman">string</font><span style="font-family: 宋体">已经</span><font face="Times New Roman">encodeURIComponent</font><span style="font-family: 宋体">了</span></font><br />
<font face="Times New Roman" size="3">getValue(element)</font><span style="font-family: 宋体"><font size="3">：返回元素的值</font></span><br />
<font face="Times New Roman" size="3">clear(element)</font><span style="font-family: 宋体"><font size="3">：清除元素的值</font></span><br />
<font face="Times New Roman" size="3">present(element)</font><span style="font-family: 宋体"><font size="3">：判断元素的值是否非空</font></span><br />
<font face="Times New Roman" size="3">activate(element)</font><span style="font-family: 宋体"><font size="3">：使元素获得焦点</font></span><br />
<font face="Times New Roman" size="3">disable(element)</font><span style="font-family: 宋体"><font size="3">：使元素不可用</font></span><br />
<font face="Times New Roman" size="3">enable(element)</font><span style="font-family: 宋体"><font size="3">：是元素可用</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">$F = Form.Element.getValue </font><span style="font-family: 宋体">方便使用</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Form.Element.Observer</font><span style="font-family: 宋体">以及</span><font face="Times New Roman">Form.Observer</font><span style="font-family: 宋体">类：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">周期性监视表单元素，如果表单或表单元素的值有改变时，执行执行一个回调函数，使用方式如下：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">var oser=new Form.Element.Observer(element, frequency, callback) <br />
or oser=new Form.Observer(form, frequency, callback) <br />
callback</font><span style="font-family: 宋体">可以定义两个参数</span><font face="Times New Roman"> form/element</font><span style="font-family: 宋体">、</span><font face="Times New Roman">Form.serialize()/value</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Form.Element.EventObserver</font><span style="font-family: 宋体">和</span><font face="Times New Roman">Form.EventObserver</font><span style="font-family: 宋体">类：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">这两个类跟上面的差不多，只是不是周期性的监视，而是利用元素的</span><font face="Times New Roman">change</font><span style="font-family: 宋体">或</span><font face="Times New Roman">click</font><span style="font-family: 宋体">事件来监视表单元素的变化，当发生变化时执行</span><font face="Times New Roman">callback</font><span style="font-family: 宋体">，参数跟上面一样</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;</font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">十二</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>event.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">在介绍</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中</span><font face="Times New Roman">Event</font><span style="font-family: 宋体">对象前先介绍一下浏览器中的事件模型，浏览器中的事件主要有</span><font face="Times New Roman">HTML</font><span style="font-family: 宋体">事件、鼠标事件和键盘事件，前两种事件比较好理解，这里主要解释一下键盘事件以及它在</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">和</span><font face="Times New Roman">firefox</font><span style="font-family: 宋体">中的区别</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">键盘事件包括</span><font face="Times New Roman">keydown</font><span style="font-family: 宋体">、</span><font face="Times New Roman">kepress</font><span style="font-family: 宋体">和</span><font face="Times New Roman">keyup</font><span style="font-family: 宋体">三种，每次敲击键盘都会</span><font face="Times New Roman">(</font><span style="font-family: 宋体">依次？</span><font face="Times New Roman">)</font><span style="font-family: 宋体">触发这三种事件，其中</span><font face="Times New Roman">keydown</font><span style="font-family: 宋体">和</span><font face="Times New Roman">keyup</font><span style="font-family: 宋体">是比较低级的接近于硬件的事件，通俗的理解是这两个事件可以捕获到你敲击了键盘中某个键；而</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">是相对于字符层面的较为高级点的事件，这个事件能够捕捉到你键入了哪个字符。可以这样理解，如果你敲击了</span><font face="Times New Roman">A</font><span style="font-family: 宋体">键，</span><font face="Times New Roman">keydown</font><span style="font-family: 宋体">和</span><font face="Times New Roman">keyup</font><span style="font-family: 宋体">事件只是知道你敲击了</span><font face="Times New Roman">A</font><span style="font-family: 宋体">键，它并不知道你敲的是大写的</span><font face="Times New Roman">A(</font><span style="font-family: 宋体">你同时按下了</span><font face="Times New Roman">Shift</font><span style="font-family: 宋体">键</span><font face="Times New Roman">)</font><span style="font-family: 宋体">还是敲的是小写</span><font face="Times New Roman">a</font><span style="font-family: 宋体">，它是以</span><font face="Times New Roman">"</font><span style="font-family: 宋体">键</span><font face="Times New Roman">"</font><span style="font-family: 宋体">为单位，你敲入了大写的</span><font face="Times New Roman">A</font><span style="font-family: 宋体">，它只是当成你敲下了</span><font face="Times New Roman">shift</font><span style="font-family: 宋体">和</span><font face="Times New Roman">A</font><span style="font-family: 宋体">两个键而已，但是</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">可以捕捉到你是敲入的大写的</span><font face="Times New Roman">A</font><span style="font-family: 宋体">还是小写的</span><font face="Times New Roman">a</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">还要理解一个概念是键盘中的键分为字符</span><font face="Times New Roman">(</font><span style="font-family: 宋体">可打印</span><font face="Times New Roman">)</font><span style="font-family: 宋体">键和功能键</span><font face="Times New Roman">(</font><span style="font-family: 宋体">不可打印</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，功能键包括</span><font face="Times New Roman">Backspace, Enter, Escape, the arrow keys, Page Up, Page Down, and F1 through F12 </font><span style="font-family: 宋体">等</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">下面说一下键盘事件的具体使用方法，</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">键盘事件的</span><font face="Times New Roman">event</font><span style="font-family: 宋体">对象中包含一个</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">属性，</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">中只有这一个属性，当为</span><font face="Times New Roman">keydown</font><span style="font-family: 宋体">和</span><font face="Times New Roman">keyup </font><span style="font-family: 宋体">事件是，</span><font face="Times New Roman">keycode</font><span style="font-family: 宋体">属性表示你具体按下的键</span><font face="Times New Roman">(</font><span style="font-family: 宋体">也称为</span><font face="Times New Roman">virtual keycode)</font><span style="font-family: 宋体">，当捕捉的是</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">事件时</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">属性指的是你键入的字符</span><font face="Times New Roman">(character code)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">在</span><font face="Times New Roman">firefox</font><span style="font-family: 宋体">中情况有些不同，</span><font face="Times New Roman">event</font><span style="font-family: 宋体">对象包含一个</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">属性和一个</span><font face="Times New Roman">charCode</font><span style="font-family: 宋体">属性，</span><font face="Times New Roman">keydown</font><span style="font-family: 宋体">和</span><font face="Times New Roman">keyup</font><span style="font-family: 宋体">事件的时候，</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">表示的就是你具体按的键，</span><font face="Times New Roman">charCode</font><span style="font-family: 宋体">为</span><font face="Times New Roman">0</font><span style="font-family: 宋体">；当捕捉的是</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">事件时，</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">为</span><font face="Times New Roman">0</font><span style="font-family: 宋体">，</span><font face="Times New Roman">charCode</font><span style="font-family: 宋体">指的是你按下的字符</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">当捕捉的是</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">事件时，</span><span style="font-family: 宋体">当你按的是可打印字符时，</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">为</span><font face="Times New Roman">0</font><span style="font-family: 宋体">，</span><font face="Times New Roman">charCode</font><span style="font-family: 宋体">指的是你按下的字符的键值，当你按的是不可打印字符时，</span><font face="Times New Roman">keyCode</font><span style="font-family: 宋体">为按下的键的键值，</span><font face="Times New Roman">charCode</font><span style="font-family: 宋体">为</span><font face="Times New Roman">0</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">注意：功能键不会触发</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">事件，因为</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">对应的就是可打印的字符，但是有一点</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">和</span><font face="Times New Roman">FF </font><span style="font-family: 宋体">中的区别，你按下一个字符键的同时按下</span><font face="Times New Roman">alt</font><span style="font-family: 宋体">键，在</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">中不触发</span><font face="Times New Roman">keypress</font><span style="font-family: 宋体">事件，但是在</span><font face="Times New Roman">ff</font><span style="font-family: 宋体">中可触发，我发现在</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">中按下</span><font face="Times New Roman">ctrl</font><span style="font-family: 宋体">键的时候只有按下</span><font face="Times New Roman"> q</font><span style="font-family: 宋体">键会触发事件其他的要么不会触发事件，要么被浏览器</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">自身捕获了，例如你按下</span><font face="Times New Roman">ctrl_A</font><span style="font-family: 宋体">，全选某个东西，你按</span><font face="Times New Roman">ctrl_S</font><span style="font-family: 宋体">保存文件，但是在</span><font face="Times New Roman">FF</font><span style="font-family: 宋体">中就</span><span style="font-family: 宋体">好多了，事件都是先传递到网页，再向外传递</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">鉴于</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">和</span><font face="Times New Roman">FF</font><span style="font-family: 宋体">中的区别，如果你比较懒的话，建议只使用</span><font face="Times New Roman">keydow</font><span style="font-family: 宋体">和</span><font face="Times New Roman">keyup</font><span style="font-family: 宋体">事件，这两种事件的使用在</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">和</span><font face="Times New Roman">FF</font><span style="font-family: 宋体">中基本上没有区别，也不要捕获</span><font face="Times New Roman">ctrl_A</font><span style="font-family: 宋体">等被浏览器定义为快捷键的事件</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">键盘事件</span><font face="Times New Roman">event</font><span style="font-family: 宋体">对象还有三个其他的属性</span><font face="Times New Roman">altKey, ctrlKey, and shiftKey </font><span style="font-family: 宋体">来判断你按下一个键的时候是否按下了</span><font face="Times New Roman">alt</font><span style="font-family: 宋体">等键，这三个属性使用比较简单，三种事件都可以使用，也不存在</span><font face="Times New Roman">ie</font><span style="font-family: 宋体">和</span><font face="Times New Roman">ff</font><span style="font-family: 宋体">的兼容性问题</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">在</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">Event</font><span style="font-family: 宋体">中又如下属性：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp; KEY_BACKSPACE: 8,<br />
&nbsp; KEY_TAB:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9,<br />
&nbsp; KEY_RETURN:&nbsp;&nbsp; 13,<br />
&nbsp; KEY_ESC:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27,<br />
&nbsp; KEY_LEFT:&nbsp;&nbsp;&nbsp;&nbsp; 37,<br />
&nbsp; KEY_UP:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 38,<br />
&nbsp; KEY_RIGHT:&nbsp;&nbsp;&nbsp; 39,<br />
&nbsp; KEY_DOWN:&nbsp;&nbsp;&nbsp;&nbsp; 40,<br />
&nbsp; KEY_DELETE:&nbsp;&nbsp; 46,<br />
&nbsp; KEY_HOME:&nbsp;&nbsp;&nbsp;&nbsp; 36,<br />
&nbsp; KEY_END:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 35,<br />
&nbsp; KEY_PAGEUP:&nbsp;&nbsp; 33,<br />
&nbsp; KEY_PAGEDOWN: 34,</font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">以及下面的方法：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">element(event) </font><span style="font-family: 宋体">：返回触发事件的元素</span></font><br />
<font face="Times New Roman" size="3">isLeftClick(event) </font><span style="font-family: 宋体"><font size="3">：判断是否按下的左键</font></span><br />
<font face="Times New Roman" size="3">pointerX(event) </font><font size="3"><span style="font-family: 宋体">：事件触发时鼠标的横坐标，对于非鼠标事件，在</span><font face="Times New Roman">ff</font><span style="font-family: 宋体">中没有此信息，但在</span><font face="Times New Roman">ie</font><span style="font-family: 宋体">中有？</span></font><br />
<font face="Times New Roman" size="3">pointerY(event)</font><span style="font-family: 宋体"><font size="3">：事件触发时鼠标所在位置的纵坐标</font></span><br />
<font face="Times New Roman" size="3">stop(event)</font><span style="font-family: 宋体"><font size="3">：阻止事件向上传播和浏览器的默认处理方法</font></span><br />
<font face="Times New Roman" size="3">findElement(event, tagName) </font><font size="3"><span style="font-family: 宋体">：找到触发事件的元素的所有祖先元素中的</span><font face="Times New Roman">tagName</font><span style="font-family: 宋体">为</span><font face="Times New Roman">tagName</font><span style="font-family: 宋体">的一个元素</span></font><br />
<font face="Times New Roman" size="3">observe(element, name, observer, useCapture)</font><span style="font-family: 宋体"><font size="3">：注册事件处理函数</font></span><br />
<font face="Times New Roman" size="3">stopObserving(element, name, observer, useCapture)</font><span style="font-family: 宋体"><font size="3">：撤销注册的事件</font></span></p>
</div>
 <img src ="http://www.blogjava.net/hummer008/aggbug/203711.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:41 <a href="http://www.blogjava.net/hummer008/articles/203711.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Prototype（1.5 rc2)使用指南（三）(转)</title><link>http://www.blogjava.net/hummer008/articles/203710.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:40:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203710.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203710.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203710.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203710.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203710.html</trackback:ping><description><![CDATA[<div>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">九</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>dom.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">这部分提供了很多</span><font face="Times New Roman">(</font><span style="font-family: 宋体">写的都有点烦了</span><font face="Times New Roman">)</font><span style="font-family: 宋体">方便的操作</span><font face="Times New Roman">dom</font><span style="font-family: 宋体">的方法：包含有名的</span><font face="Times New Roman">$</font><span style="font-family: 宋体">方法、</span><font face="Times New Roman">document.getElementsByClassName</font><span style="font-family: 宋体">方法，以及</span><font face="Times New Roman">Element</font><span style="font-family: 宋体">对象、</span><font face="Times New Roman">Insertion</font><span style="font-family: 宋体">对象</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">以下部分一个一个的详细介绍：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">$(element)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">getElementById</font><span style="font-family: 宋体">的封装，</span><font face="Times New Roman">element</font><span style="font-family: 宋体">可以是一个元素的</span><font face="Times New Roman">id</font><span style="font-family: 宋体">或元素本身，也可以是一个数组，这时返回一个数组，使用</span><font face="Times New Roman">$</font><span style="font-family: 宋体">方法，会自动调用</span><font face="Times New Roman">Element.extend(element)</font><span style="font-family: 宋体">方法，这样的话使元素可以直接调用</span><font face="Times New Roman"> Element</font><span style="font-family: 宋体">中的方法</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">Element.hide(element)</font><span style="font-family: 宋体">可以写成这样</span><font face="Times New Roman">$(element).hide()</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">document.getElementsByClassName(className, parentElement): </font><span style="font-family: 宋体">根据</span><font face="Times New Roman">class</font><span style="font-family: 宋体">选择元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Element.extend(element): </font><span style="font-family: 宋体">扩展</span><font face="Times New Roman">element</font><span style="font-family: 宋体">，使</span><font face="Times New Roman">element</font><span style="font-family: 宋体">可以直接调用</span><font face="Times New Roman">Element</font><span style="font-family: 宋体">、</span><font face="Times New Roman">Form.Element</font><span style="font-family: 宋体">或</span><font face="Times New Roman">Form</font><span style="font-family: 宋体">中定义的方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Element</font><span style="font-family: 宋体">对象的方法：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">visible: function(element)</font><span style="font-family: 宋体">：判断</span><font face="Times New Roman">element</font><span style="font-family: 宋体">是否可见</span><font face="Times New Roman">, </font><span style="font-family: 宋体">参数</span><font face="Times New Roman">element</font><span style="font-family: 宋体">可以是元素本身或元素</span><font face="Times New Roman">id(</font><span style="font-family: 宋体">下面的方面的参数基本上都是这样的</span><font face="Times New Roman">)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">toggle: function(element)</font><span style="font-family: 宋体">：反转</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的可见性</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">hide: function(element)</font><span style="font-family: 宋体">：隐藏元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">show: function(element)</font><span style="font-family: 宋体">：显示元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">remove: function(element)</font><span style="font-family: 宋体">：移除元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">update: function(element, html) </font><span style="font-family: 宋体">：使用</span><font face="Times New Roman">html</font><span style="font-family: 宋体">更新</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的内容，</span><font face="Times New Roman">html</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">script</font><span style="font-family: 宋体">会执行</span><font face="Times New Roman">(</font><span style="font-family: 宋体">下同</span><font face="Times New Roman">)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">replace: function(element, html)</font><span style="font-family: 宋体">：将</span><font face="Times New Roman">element</font><span style="font-family: 宋体">替换为</span><font face="Times New Roman">html</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inspect: function(element)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的字符串表示</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">recursivelyCollect: function(element, property): </font><span style="font-family: 宋体">递归收集</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">Element.recursivelyCollect(element, "parentNode")</font><span style="font-family: 宋体">返回</span><font face="Times New Roman">element</font><span style="font-family: 宋体">所有的祖先节点</span><font face="Times New Roman">, </font><span style="font-family: 宋体">注意只返回</span><font face="Times New Roman">nodeType == 1</font><span style="font-family: 宋体">的元素，也就是不返回文本元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">ancestors: function(element): </font><span style="font-family: 宋体">等同于上面的例子，返回元素的所有祖先节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">descendants: function(element): </font><span style="font-family: 宋体">返回所有子孙节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">immediateDescendants: function(element)</font><span style="font-family: 宋体">：返回元素的直接的子孙节点</span><font face="Times New Roman">(</font><span style="font-family: 宋体">子节点</span><font face="Times New Roman">)</font><span style="font-family: 宋体">的数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">previousSiblings: function(element)</font><span style="font-family: 宋体">：返回元素前面的兄弟节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">nextSiblings: function(element)</font><span style="font-family: 宋体">：返回位于元素后面的兄弟节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">siblings: function(element)</font><span style="font-family: 宋体">：返回元素所有的兄弟节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">match: function(element, selector)</font><span style="font-family: 宋体">：使用</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">的</span><font face="Times New Roman">match</font><span style="font-family: 宋体">方法匹配元素</span><font face="Times New Roman">(Selector</font><span style="font-family: 宋体">将在后面介绍</span><font face="Times New Roman">), selector</font><span style="font-family: 宋体">参数是一个</span><font face="Times New Roman">css selector</font><span style="font-family: 宋体">表达式或者</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中的一个</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">实例，如果</span><font face="Times New Roman">element</font><span style="font-family: 宋体">匹配</span><font face="Times New Roman">selector</font><span style="font-family: 宋体">则返回</span><font face="Times New Roman">true</font><span style="font-family: 宋体">，否则返回</span><font face="Times New Roman"> false</font><span style="font-family: 宋体">，例如对于一个</span><font face="Times New Roman">className</font><span style="font-family: 宋体">为</span><font face="Times New Roman">logcss</font><span style="font-family: 宋体">的</span><font face="Times New Roman">div</font><span style="font-family: 宋体">来说，下面的表达式返回</span><font face="Times New Roman">true, $(element).match("div.logcss") </font><span style="font-family: 宋体">待续。。</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">up(element, expression, index)</font><span style="font-family: 宋体">：利用</span><font face="Times New Roman">Selector.findElement</font><span style="font-family: 宋体">方法找到</span><font face="Times New Roman">element</font><span style="font-family: 宋体">元素的祖先节点中符合表达式</span><font face="Times New Roman">expression</font><span style="font-family: 宋体">的所有元素组成的数组索引为</span><font face="Times New Roman">index</font><span style="font-family: 宋体">的元素，也可以忽略</span><font face="Times New Roman">expression(</font><span style="font-family: 宋体">默认为</span><font face="Times New Roman">*</font><span style="font-family: 宋体">，表示匹配所有元素</span><font face="Times New Roman">)</font><span style="font-family: 宋体">和</span><font face="Times New Roman">index(</font><span style="font-family: 宋体">默认为</span><font face="Times New Roman">0)</font><span style="font-family: 宋体">，直接这样调用</span><font face="Times New Roman">up(element, index)</font><span style="font-family: 宋体">或</span><font face="Times New Roman">up(element)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">down(element, expression, index)</font><span style="font-family: 宋体">：跟</span><font face="Times New Roman">up</font><span style="font-family: 宋体">一样，只是返回的是子孙节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">previous(element, expression, index)</font><span style="font-family: 宋体">：返回前面的兄弟节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">next(element, expression, index)</font><span style="font-family: 宋体">：返回后面的兄弟节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">getElementsBySelector(element,args)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">Selector.findChildElements(element, args)</font><span style="font-family: 宋体">的封装，</span><font face="Times New Roman">args</font><span style="font-family: 宋体">表示可以传递多个参数，每个参数是一个</span><font face="Times New Roman">css selector</font><span style="font-family: 宋体">表达式，返回</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的子孙节点中符合任何一个</span><font face="Times New Roman">css selector</font><span style="font-family: 宋体">表达式的元素组成的数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">getElementsByClassName(element, className)</font><span style="font-family: 宋体">：返回</span><font face="Times New Roman">element</font><span style="font-family: 宋体">中的子孙节点中符合</span><font face="Times New Roman">clsssName</font><span style="font-family: 宋体">的元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">readAttribute(element, name)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">return $(element).getAttribute(name)</font><span style="font-family: 宋体">，之所以添加这个方法是因为在</span><font face="Times New Roman">IE</font><span style="font-family: 宋体">和</span><font face="Times New Roman">Safari(Mac)</font><span style="font-family: 宋体">中</span><font face="Times New Roman">getAttribute</font><span style="font-family: 宋体">不是一个真正的函数，它没有</span><font face="Times New Roman">call</font><span style="font-family: 宋体">、</span><font face="Times New Roman">apply</font><span style="font-family: 宋体">等方法，所以在很多时候调用会出现错误</span><font face="Times New Roman">(Prototype</font><span style="font-family: 宋体">中很多地方使用了函数的这两个方法</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，例如下面的例子</span><font face="Times New Roman">(</font><span style="font-family: 宋体">官方文档中的一个例子</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，就只能使用</span><font face="Times New Roman">readAttribute</font><span style="font-family: 宋体">：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&lt;div id="widgets"&gt;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&lt;div class="widget" widget_id="7"&gt;&#8230;&lt;/div&gt;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&lt;div class="widget" widget_id="8"&gt;&#8230;&lt;/div&gt;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&lt;div class="widget" widget_id="9"&gt;&#8230;&lt;/div&gt;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&lt;/div&gt;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">$$(&#8217;div.widget&#8217;).invoke(&#8217;readAttribute&#8217;, 'widget_id&#8217;)</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">// ["7", "8", "9"]</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">getHeight: function(element)</font><span style="font-family: 宋体">：返回元素高度，</span><font face="Times New Roman">return element.offsetHeight</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">classNames: function(element)</font><span style="font-family: 宋体">：返回一个</span><font face="Times New Roman">Element.ClassNames</font><span style="font-family: 宋体">对象，改对象提供对元素</span><font face="Times New Roman">class</font><span style="font-family: 宋体">的操作，包括</span><font face="Times New Roman">add</font><span style="font-family: 宋体">、</span><font face="Times New Roman">remove</font><span style="font-family: 宋体">、</span><font face="Times New Roman">set</font><span style="font-family: 宋体">等，一般很少使用，使用</span><font face="Times New Roman">Element.addClassName</font><span style="font-family: 宋体">等方法就可以了</span><font face="Times New Roman">(</font><span style="font-family: 宋体">就在下面</span><font face="Times New Roman">)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">hasClassName: function(element, className) </font><span style="font-family: 宋体">：判断</span><font face="Times New Roman">element</font><span style="font-family: 宋体">是否含有</span><font face="Times New Roman">className</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">addClassName: function(element, className) </font><span style="font-family: 宋体">：给</span><font face="Times New Roman">element</font><span style="font-family: 宋体">添加一个</span><font face="Times New Roman">class</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">removeClassName: function(element, className) </font><span style="font-family: 宋体">：移除元素中的一个</span><font face="Times New Roman">class</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">observe()</font><span style="font-family: 宋体">：调用</span><font face="Times New Roman">Event</font><span style="font-family: 宋体">对象</span><font face="Times New Roman">(Prototype</font><span style="font-family: 宋体">中的，将在后面介绍</span><font face="Times New Roman">)</font><span style="font-family: 宋体">的</span><font face="Times New Roman">observe</font><span style="font-family: 宋体">方法为元素注册事件</span><font face="Times New Roman">handle</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">stopObserving() </font><span style="font-family: 宋体">：移除注册的事件</span><font face="Times New Roman">handle</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">cleanWhitespace: function(element)</font><span style="font-family: 宋体">：移除元素中空白的文本子节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">empty: function(element)</font><span style="font-family: 宋体">：判断元素是否为空</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">childOf: function(element, ancestor) </font><span style="font-family: 宋体">：判断</span><font face="Times New Roman">element</font><span style="font-family: 宋体">是否为</span><font face="Times New Roman">ancestor</font><span style="font-family: 宋体">的子孙节点</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">scrollTo: function(element) </font><span style="font-family: 宋体">：滚动条移动到元素所在的地方</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">getStyle: function(element, style) </font><span style="font-family: 宋体">：得到元素某个</span><font face="Times New Roman">css</font><span style="font-family: 宋体">样式的值，例如</span><font face="Times New Roman">$(element).getStyle("float")</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">setStyle: function(element, style) </font><span style="font-family: 宋体">：设置元素的</span><font face="Times New Roman">css</font><span style="font-family: 宋体">样式，</span><font face="Times New Roman">style</font><span style="font-family: 宋体">十一个对象，例如</span><font face="Times New Roman">element.setStyle({left: "40px", "background-color":"#666"})</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">getDimensions: function(element) </font><span style="font-family: 宋体">：得到元素的尺寸，即使元素是隐藏的也可以正确的返回，返回</span><font face="Times New Roman"> return {width: originalWidth, height: originalHeight}</font><span style="font-family: 宋体">这样的关联数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">makePositioned: function(element) </font><span style="font-family: 宋体">：当元素的</span><font face="Times New Roman">position css</font><span style="font-family: 宋体">属性为</span><font face="Times New Roman">static</font><span style="font-family: 宋体">或不存在使，将次属性更改为</span><font face="Times New Roman">relative</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">undoPositioned: function(element) </font><span style="font-family: 宋体">：跟</span><font face="Times New Roman">makePositioned</font><span style="font-family: 宋体">相反的操作</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">makeClipping: function(element) </font><span style="font-family: 宋体">：把元素变成</span><font face="Times New Roman">clipping(</font><span style="font-family: 宋体">切片</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，也就是设置元素的</span><font face="Times New Roman">overflow</font><span style="font-family: 宋体">属性为</span><font face="Times New Roman">hidden</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">undoClipping: function(element)</font><span style="font-family: 宋体">：反转上面的方法对元素所做的修改</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">hasAttribute(element)</font><span style="font-family: 宋体">：判断元素是否有某个属性</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Element</font><span style="font-family: 宋体">对象的方法是不是不少啊，哈哈，下面介绍有关</span><font face="Times New Roman">Insertion</font><span style="font-family: 宋体">的四个类</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Insertion.Before</font><span style="font-family: 宋体">：将内容插入到元素的前面，内容在元素外面</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Insertion.Top</font><span style="font-family: 宋体">：将内容插入到元素的顶部，内容在元素里面</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Insertion.Bottom</font><span style="font-family: 宋体">：将内容插入到元素的底部，内容在元素里面</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Insertion.After</font><span style="font-family: 宋体">：将内容插入到元素后面，内容在元素外面</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">使用它们的方法比较简单：</span><font face="Times New Roman">new Insertion.where(element, content)</font><span style="font-family: 宋体">，其中</span><font face="Times New Roman">where</font><span style="font-family: 宋体">表示上面的</span><font face="Times New Roman">Before</font><span style="font-family: 宋体">、</span><font face="Times New Roman">Top</font><span style="font-family: 宋体">等，</span><font face="Times New Roman">content</font><span style="font-family: 宋体">是</span><font face="Times New Roman">html</font><span style="font-family: 宋体">字符串，注意其中</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">片断会执行</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">终于写完了，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">的</span><font face="Times New Roman">Element</font><span style="font-family: 宋体">方法还真不少</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">虽然以前觉得自己对</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">还比较熟悉，写的也有点累，但是发现自己收获仍然挺大的，为了写出这些方法的具体作用和用法，必须强迫自己一行行的把</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">的代码弄清楚，使自己对</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中很多精巧的写法有了更深刻的认识和理解</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">写这个教程的主要目的是为了给大家一个快速的参考，大家还是对照着源代码看才会真正有所提高</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">这时我第一次写比较完整的一个教程，错误幼稚的地方在所难免，希望大家批评指正，互相学习提高，</font></span></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">十</span>).Prototype<span style="font-family: 黑体">使用指南之</span><span style="font-size: 12pt; line-height: 173%; font-family: 宋体">Selector</span></font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Selector</font><span style="font-family: 宋体">是利用</span><font face="Times New Roman">css selector</font><span style="font-family: 宋体">来匹配选择页面元素的，所以要理解</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">首先应该对</span><font face="Times New Roman">css selector</font><span style="font-family: 宋体">有所理解，下面是</span><font face="Times New Roman">css2 selector</font><span style="font-family: 宋体">的语法，当然很多浏览器只是支持其中的一部分，</span><font face="Times New Roman">Prototype </font><span style="font-family: 宋体">中的</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">主要支持</span><font face="Times New Roman">tag</font><span style="font-family: 宋体">选择器、</span><font face="Times New Roman">class</font><span style="font-family: 宋体">选择器和</span><font face="Times New Roman">id</font><span style="font-family: 宋体">选择器，还有属性</span><font face="Times New Roman">(attribute)</font><span style="font-family: 宋体">选择器，基本上包含我们平时所用的所有类型</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">The following table summarizes CSS2 selector syntax, </font><span style="font-family: 宋体">详细的可以看</span><a href="http://www.w3.org/TR/REC-CSS2/selector.html"><font face="Times New Roman" color="#666666">http://www.w3.org/TR/REC-CSS2/selector.html</font></a><font face="Times New Roman">: </font></font></p>
<table cellpadding="0" border="1">
    <tbody>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Pattern</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Meaning</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Described in section</font></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">*</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any element.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#universal-selector"><font face="Times New Roman" color="#666666" size="3">Universal selector</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any E element (i.e., an element of type E).</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#type-selectors"><font face="Times New Roman" color="#666666" size="3">Type selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E F</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any F element that is a descendant of an E element.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#descendant-selectors"><font face="Times New Roman" color="#666666" size="3">Descendant selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E &gt; F</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any F element that is a child of an element E.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#child-selectors"><font face="Times New Roman" color="#666666" size="3">Child selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E:first-child</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches element E when E is the first child of its parent.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#first-child"><font face="Times New Roman" color="#666666" size="3">The :first-child pseudo-class</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E:link E:visited</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">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).</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#link-pseudo-classes"><font face="Times New Roman" color="#666666" size="3">The link pseudo-classes</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E:active E:hover E:focus</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches E during certain user actions.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#dynamic-pseudo-classes"><font face="Times New Roman" color="#666666" size="3">The dynamic pseudo-classes</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E:lang(c)</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches element of type E if it is in (human) language c (the document language specifies how language is determined).</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#lang"><font face="Times New Roman" color="#666666" size="3">The :lang() pseudo-class</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E + F</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any F element immediately preceded by an element E.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#adjacent-selectors"><font face="Times New Roman" color="#666666" size="3">Adjacent selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E[foo]</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any E element with the &#8220;foo&#8221; attribute set (whatever the value).</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#attribute-selectors"><font face="Times New Roman" color="#666666" size="3">Attribute selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E[foo=&#8221;warning&#8221;]</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any E element whose &#8220;foo&#8221; attribute value is exactly equal to &#8220;warning&#8221;.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#attribute-selectors"><font face="Times New Roman" color="#666666" size="3">Attribute selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E[foo~=&#8221;warning&#8221;]</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any E element whose &#8220;foo&#8221; attribute value is a list of space-separated values, one of which is exactly equal to &#8220;warning&#8221;.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#attribute-selectors"><font face="Times New Roman" color="#666666" size="3">Attribute selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E[lang|=&#8221;en&#8221;]</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any E element whose &#8220;lang&#8221; attribute has a hyphen-separated list of values beginning (from the left) with &#8220;en&#8221;.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#attribute-selectors"><font face="Times New Roman" color="#666666" size="3">Attribute selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">DIV.warning</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">HTML only. The same as DIV[class~=&#8221;warning&#8221;].</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#class-html"><font face="Times New Roman" color="#666666" size="3">Class selectors</font></a></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">E#myid</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Matches any E element ID equal to &#8220;myid&#8221;.</font></p>
            </td>
            <td style="border-right: #ece9d8; padding-right: 0.75pt; border-top: #ece9d8; padding-left: 0.75pt; padding-bottom: 0.75pt; border-left: #ece9d8; padding-top: 0.75pt; border-bottom: #ece9d8; background-color: transparent">
            <p style="margin: 0cm 0cm 0pt"><a href="http://www.7tt.com.cn/perol/2006/12/01/prototype_selector_javascript/#id-selectors"><font face="Times New Roman" color="#666666" size="3">ID selectors</font></a></p>
            </td>
        </tr>
    </tbody>
</table>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Selector</font><span style="font-family: 宋体">中包含</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">对象和类，</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Selector</font><span style="font-family: 宋体">对象具有下面两个方法：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">match(element)</font><span style="font-family: 宋体">：元素是否与本</span><font face="Times New Roman">selector</font><span style="font-family: 宋体">匹配，在</span><font face="Times New Roman">Element</font><span style="font-family: 宋体">中已经介绍了</span></font><br />
<font face="Times New Roman" size="3">findElements(parentNode)</font><font size="3"><span style="font-family: 宋体">：</span><font face="Times New Roman">parentNode</font><span style="font-family: 宋体">中所有匹配本</span><font face="Times New Roman">selector</font><span style="font-family: 宋体">的子孙元素列表</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">使用方法也很简单</span><font face="Times New Roman"> var s=new Selector(expression); s.match(element); s.findElements($(element))</font><span style="font-family: 宋体">，其中</span><font face="Times New Roman">expression</font><span style="font-family: 宋体">可以是如下方式</span><font face="Times New Roman"> "div"</font><span style="font-family: 宋体">、</span><font face="Times New Roman">"#id"</font><span style="font-family: 宋体">、</span><font face="Times New Roman">".class"</font><span style="font-family: 宋体">、</span><font face="Times New Roman">"div#id"</font><span style="font-family: 宋体">、</span><font face="Times New Roman">"div[attribute]"</font><span style="font-family: 宋体">、</span><font face="Times New Roman">"div[attribute=fff]"</font><span style="font-family: 宋体">、</span><font face="Times New Roman">"div[attribute!=sdf]"</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">其中</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">也有几个静态方法，它们分别是：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">matchElements(elements, expression)</font><span style="font-family: 宋体">：返回</span><font face="Times New Roman">elements</font><span style="font-family: 宋体">中符合</span><font face="Times New Roman">expression</font><span style="font-family: 宋体">的元素列表</span></font><br />
<font face="Times New Roman" size="3">findElement(elements, expression, index)</font><font size="3"><span style="font-family: 宋体">：返回</span><font face="Times New Roman">elements</font><span style="font-family: 宋体">中符合</span><font face="Times New Roman">expression</font><span style="font-family: 宋体">的元素列表中索引为</span><font face="Times New Roman">index</font><span style="font-family: 宋体">的元素</span></font><br />
<font face="Times New Roman" size="3">findChildElements(element, expressions)</font><font size="3"><span style="font-family: 宋体">：找出</span><font face="Times New Roman">element</font><span style="font-family: 宋体">的子孙元素中符合</span><font face="Times New Roman">expressions</font><span style="font-family: 宋体">的元素列表，其中</span><font face="Times New Roman">expressions</font><span style="font-family: 宋体">是一个</span><font face="Times New Roman">expression</font><span style="font-family: 宋体">数组，其中的</span><font face="Times New Roman">expression</font><span style="font-family: 宋体">支持</span><font face="Times New Roman">"div li.#id"</font><span style="font-family: 宋体">形式</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">$$</font><span style="font-family: 宋体">方法：只是简单的调用</span><font face="Times New Roman">return Selector.findChildElements(document, $A(arguments))</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">虽然</span><font face="Times New Roman">Selector</font><span style="font-family: 宋体">有这么多方法，但是大部分都是内部调用的，我们一般都很少使用，因为我们有个一个方便的方法</span><font face="Times New Roman">$$</font><span style="font-family: 宋体">，对于绝大部分情况已经足够了</span></font></p>
</div>
 <img src ="http://www.blogjava.net/hummer008/aggbug/203710.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:40 <a href="http://www.blogjava.net/hummer008/articles/203710.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Prototype（1.5 rc2)使用指南（一） 转</title><link>http://www.blogjava.net/hummer008/articles/203707.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:37:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203707.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203707.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203707.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203707.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203707.html</trackback:ping><description><![CDATA[<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">一</span>).<span style="font-family: 黑体">序言</span></font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">在写这个指南之前，先介绍一下</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">主要是干吗的，如果你比较关注</span><font face="Times New Roman">ajax/javascipt</font><span style="font-family: 宋体">方面的应用，你应该早就听说过这个</span><font face="Times New Roman"> javascript framework</font><span style="font-family: 宋体">。</span><font face="Times New Roman"> Prototype</font><span style="font-family: 宋体">是一个基础的</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">应用框架，先引用一段官方网站的介绍</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Prototype is a JavaScript framework that aims to ease development of dynamic web applications. Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around, Prototype is quickly becoming the codebase of choice for web application developers everywhere.</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">根据作者自己的介绍，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">的目的是为了更方便的开发</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">的应用，使用它可以更加方便简单的使用</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">编程，开发出面向对象的</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">程序，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中包含包含了一个功能强大好用的</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">框架，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">是一个基础性的框架，很多更高层次的框架都以它为基础，例如</span><font face="Times New Roman">scriptaculous</font><span style="font-family: 宋体">效果库</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中包含一下几个部分：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">base: Prototype</font><span style="font-family: 宋体">中应用的基本功能，基本上其他所有部分都依赖于它，包括用于面向对象风格的</span><font face="Times New Roman">Class.create</font><span style="font-family: 宋体">和</span><font face="Times New Roman">Object.extend</font><span style="font-family: 宋体">，一个</span><font face="Times New Roman">Try</font><span style="font-family: 宋体">对象，函数绑定，</span><font face="Times New Roman">number</font><span style="font-family: 宋体">扩展，</span><font face="Times New Roman">PeriodicalExecuter(</font><span style="font-family: 宋体">周期性执行某个函数的功能</span><font face="Times New Roman">)</font><span style="font-family: 宋体">等</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">string: </font><span style="font-family: 宋体">对</span><font face="Times New Roman">String</font><span style="font-family: 宋体">原型的扩展，为</span><font face="Times New Roman">string</font><span style="font-family: 宋体">添加了</span><font face="Times New Roman">strip,escapeHTML</font><span style="font-family: 宋体">等等好用的方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">enumerable: </font><span style="font-family: 宋体">枚举类型</span><font face="Times New Roman">(array, hash, range</font><span style="font-family: 宋体">等</span><font face="Times New Roman">)</font><span style="font-family: 宋体">的父类对象，提供枚举类型的共同方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">array: </font><span style="font-family: 宋体">对</span><font face="Times New Roman">Array</font><span style="font-family: 宋体">原型的扩展，为</span><font face="Times New Roman">array</font><span style="font-family: 宋体">添加了</span><font face="Times New Roman">indexOf</font><span style="font-family: 宋体">、</span><font face="Times New Roman">without</font><span style="font-family: 宋体">等方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">hash: </font><span style="font-family: 宋体">为</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">提供了一个好用简单的</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">实现</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">range: </font><span style="font-family: 宋体">继承于</span><font face="Times New Roman">enumerable</font><span style="font-family: 宋体">，一个范围</span><font face="Times New Roman">(</font><span style="font-family: 宋体">例如</span><font face="Times New Roman">3</font><span style="font-family: 宋体">—</span><font face="Times New Roman">67)</font><span style="font-family: 宋体">对象</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">ajax: </font><span style="font-family: 宋体">一个功能强大好用的</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">框架</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">dom: </font><span style="font-family: 宋体">对基于浏览器的开发提供了很好的跨浏览器封装，并添加很多强大的功能</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">selector: </font><span style="font-family: 宋体">提供了使用</span><font face="Times New Roman">class</font><span style="font-family: 宋体">，</span><font face="Times New Roman">css</font><span style="font-family: 宋体">等选择元素的功能</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">form: </font><span style="font-family: 宋体">关于表单的一些功能</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">event: </font><span style="font-family: 宋体">简单的夸平台事件封装</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">position: </font><span style="font-family: 宋体">提供了一些关于元素位置方面的功能</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">可以说</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">就想一把瑞士军刀，为</span><font face="Times New Roman">javascipt</font><span style="font-family: 宋体">封装了很多通用的功能，大大简化了</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">应用的开发，给</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">开发人员增添了很大的信心，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">可以运行于以下平台，使用它再也不用各种跨平台等问题烦恼了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">* Microsoft Internet Explorer for Windows, version 6.0 and higher</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">* Mozilla Firefox 1.0/Mozilla 1.7 and higher</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">* Apple Safari 1.2 and higher</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">不过要注意的是：要想很好的理解</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">，应该首先理解一下</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">面向对象开发的一些知识以后的文章将对</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中具体的每个功能中的方法做一个详细的介绍，包括作用，实例等</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">官方网站是：</span><font face="Times New Roman">http://prototype.conio.net/ </font><span style="font-family: 宋体">，目前发布版还只是</span><font face="Times New Roman">1.4, </font><span style="font-family: 宋体">但是现在的</span><font face="Times New Roman">1.5</font><span style="font-family: 宋体">已经发生了很大的变化，而且很多基于</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">的库使用的都是</span><font face="Times New Roman">1.5</font><span style="font-family: 宋体">的，所以强烈建议通过</span><font face="Times New Roman">svn</font><span style="font-family: 宋体">下载最新版代码</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;</font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">二</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>base.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">base.js</font><span style="font-family: 宋体">中包含下面的内容</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">类的创建与继承：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Class.create(): </font><span style="font-family: 宋体">创建一个类，例如</span><font face="Times New Roman"> person=Class.create()</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object.extend(destination, source): </font><span style="font-family: 宋体">把</span><font face="Times New Roman">source</font><span style="font-family: 宋体">中方法属性</span><font face="Times New Roman">copy</font><span style="font-family: 宋体">到</span><font face="Times New Roman">destination(</font><span style="font-family: 宋体">使用</span><font face="Times New Roman">for property in source)</font><span style="font-family: 宋体">，需要注意的是，</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">中除了基本类型</span><font face="Times New Roman">(Number, Boolean)</font><span style="font-family: 宋体">外都是引用类型，所以这种</span><font face="Times New Roman">copy</font><span style="font-family: 宋体">一般只是</span><font face="Times New Roman">copy</font><span style="font-family: 宋体">引用而已，</span><font face="Times New Roman">destination</font><span style="font-family: 宋体">和</span><font face="Times New Roman">source</font><span style="font-family: 宋体">还是指向同一个方法或对象属性</span><font face="Times New Roman"> (function array object)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">在面向对象的编程中，一般通过</span><font face="Times New Roman">Class.create</font><span style="font-family: 宋体">新建一个类，如果这个类继承于另一个类，一般使用</span><font face="Times New Roman">Object.extend (class.prototype, parentClass.prototype)</font><span style="font-family: 宋体">或者</span><font face="Times New Roman">Object.extend(class.prototype, aparentClassInstance)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object</font><span style="font-family: 宋体">构造函数的扩展：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object</font><span style="font-family: 宋体">是其他对象实例的构造函数</span><font face="Times New Roman">(var a=new Object())</font><span style="font-family: 宋体">，也是所有其他类的父类，对</span><font face="Times New Roman">Object</font><span style="font-family: 宋体">直接扩展</span><font face="Times New Roman">(</font><span style="font-family: 宋体">注意不是扩展</span><font face="Times New Roman">Object.prototype</font><span style="font-family: 宋体">，扩展</span><font face="Times New Roman"> Object.prototype</font><span style="font-family: 宋体">相当于添加实例方法</span><font face="Times New Roman">)</font><span style="font-family: 宋体">相当于为</span><font face="Times New Roman">Object</font><span style="font-family: 宋体">类添加静态方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object.inspect(object): </font><span style="font-family: 宋体">调用</span><font face="Times New Roman">object</font><span style="font-family: 宋体">的</span><font face="Times New Roman">inspect(</font><span style="font-family: 宋体">如果定义了</span><font face="Times New Roman">)</font><span style="font-family: 宋体">或</span><font face="Times New Roman">toString</font><span style="font-family: 宋体">方法，返回一个对象的字符串表示</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object.keys(object): </font><span style="font-family: 宋体">返回一个对象的所有属性和方法名称组成的数组</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">Object.keys(document.body)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object.values(object):</font><span style="font-family: 宋体">返回一个对象的所有属性和方法的值组成的数组</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">Object.values(docuement)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Object.clone(object): </font><span style="font-family: 宋体">返回一个对象的</span><font face="Times New Roman">clone</font><span style="font-family: 宋体">版本，其实是执行</span><font face="Times New Roman">Object.extent</font><span style="font-family: 宋体">方法把</span><font face="Times New Roman">object</font><span style="font-family: 宋体">中的方法属性</span><font face="Times New Roman">copy</font><span style="font-family: 宋体">到一个新对象中，然后返回这个对象</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">函数邦定：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">定义了</span><font face="Times New Roman">Function</font><span style="font-family: 宋体">对象的两个方法，</span><font face="Times New Roman">bind</font><span style="font-family: 宋体">和</span><font face="Times New Roman">bindAsEventListener</font><span style="font-family: 宋体">，这两个方法是一个函数的两个方法，对于</span><font face="Times New Roman">java</font><span style="font-family: 宋体">、</span><font face="Times New Roman">c#</font><span style="font-family: 宋体">程序员来说，看到这个也许感到很惊讶，因为在他们看来函数只是一个程序语句组织结构而已—</span><font face="Times New Roman">&gt;</font><span style="font-family: 宋体">怎么还有方法，而且还可以扩展？这也是</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">等脚本语言相对于</span><font face="Times New Roman">java</font><span style="font-family: 宋体">等一个非常强大的功能，函数也是一个对象，函数名就是这个对象的名称，只要你愿意，你也可以使用</span><font face="Times New Roman"> new Function(</font><span style="font-family: 宋体">&#8230;</span><font face="Times New Roman">)</font><span style="font-family: 宋体">来定义函数，所以为函数定义方法也就很正常不过了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">这两个函数的主要作用是为了解决使用</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">面向对象风格编程中</span><font face="Times New Roman">this</font><span style="font-family: 宋体">的引用问题，在</span><font face="Times New Roman">javasctipt</font><span style="font-family: 宋体">中</span><font face="Times New Roman">this</font><span style="font-family: 宋体">关键字始终指向调用该函数的对象或者指向使用</span><font face="Times New Roman">call</font><span style="font-family: 宋体">，</span><font face="Times New Roman">apply</font><span style="font-family: 宋体">方法指定的对象（具体这方面的知识可以自己</span><font face="Times New Roman">google</font><span style="font-family: 宋体">一下，以下系列对</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">的介绍也假设读者对</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">语言比较熟悉了，如果不熟悉可以找本</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">权威指南这本书看看）</span><span style="font-family: 宋体">要理解这个问题首先要理解</span><span style="font-family: 宋体">始终指向这个问题，就是</span><font face="Times New Roman">this</font><span style="font-family: 宋体">这个关键字比较特殊，不能把他当成一般的变量名看待，最常见的一个错误就是在返回函数的调用中使用</span><font face="Times New Roman">this</font><span style="font-family: 宋体">，例如</span><font face="Times New Roman">return function(){this.aMethod()}, </font><span style="font-family: 宋体">当你下次调用这个返回的匿名方法时，这个</span><font face="Times New Roman">this</font><span style="font-family: 宋体">引用的内容又指向了调用这个函数的对象了，记住的一点的</span><font face="Times New Roman">this</font><span style="font-family: 宋体">是个关键字，不是变量名，不会产生闭包</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">对</span><font face="Times New Roman">Number</font><span style="font-family: 宋体">的扩展</span><font face="Times New Roman">(</font><span style="font-family: 宋体">注意</span><font face="Times New Roman">num</font><span style="font-family: 宋体">也可以看成对象，其实是在使用的时候系统自动打包成</span><font face="Times New Roman">Number</font><span style="font-family: 宋体">对象</span><font face="Times New Roman">)</font><span style="font-family: 宋体">：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">toColorPart</font><span style="font-family: 宋体">：把数字转换为可以用于表示</span><font face="Times New Roman">color</font><span style="font-family: 宋体">的</span><font face="Times New Roman">16</font><span style="font-family: 宋体">进制值：例如</span><font face="Times New Roman"> 7.toColorPart()=&gt;"07"</font><span style="font-family: 宋体">，</span><font face="Times New Roman">28.toColorPart()=&gt;"1C"</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">succ: </font><span style="font-family: 宋体">返回</span><font face="Times New Roman">num++, </font><span style="font-family: 宋体">但不改变</span><font face="Times New Roman">num</font><span style="font-family: 宋体">本身的值，其实就是</span><font face="Times New Roman"> return this</font><span style="font-family: 宋体">＋</span><font face="Times New Roman">1</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">times</font><span style="font-family: 宋体">：对从</span><font face="Times New Roman">0</font><span style="font-family: 宋体">到这个数字轮流调用一个函数</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">function a(n){docuement.write(n)}, 10.times(a), </font><span style="font-family: 宋体">将显示</span><font face="Times New Roman">012345678910, </font><span style="font-family: 宋体">注意函数也是一个对象，而且与其他对象并没有实质的区别</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Try</font><span style="font-family: 宋体">对象：</span><font face="Times New Roman"> Try</font><span style="font-family: 宋体">对象提供了一个很有趣的功能</span><font face="Times New Roman">, </font><span style="font-family: 宋体">先看一下如下的代码：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">var Ajax = {&nbsp;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">getTransport: function() {&nbsp;&nbsp;&nbsp; </font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp; return Try.these(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function() {return new XMLHttpRequest()},&nbsp;&nbsp;&nbsp;&nbsp; </font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function() {return new ActiveXObject(&#8217;Msxml2.XMLHTTP&#8217;)},&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function() {return new ActiveXObject(&#8217;Microsoft.XMLHTTP&#8217;)}&nbsp;&nbsp; )</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp;&nbsp; || false;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp; }</font></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">｝</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Try</font><span style="font-family: 宋体">对象提供了一个方法</span><font face="Times New Roman">these, </font><span style="font-family: 宋体">这个方法接受一个函数类型的参数列表，然后轮流执行这些函数，当其中一个函数没有产生错误时，就停止执行，并且返回这个函数返回的值，自己慢慢体会吧</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">PeriodicalExecuter(</font><span style="font-family: 宋体">周期性执行器</span><font face="Times New Roman">)</font><span style="font-family: 宋体">对象</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">这个对象是对</span><font face="Times New Roman">setInterval</font><span style="font-family: 宋体">方法的简单封装，使用方法如下</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">var a=new PeriodicalExecuter(callback, frequency ) </font><span style="font-family: 宋体">，其中</span><font face="Times New Roman">callback</font><span style="font-family: 宋体">指要执行的函数名</span><font face="Times New Roman"> frequency</font><span style="font-family: 宋体">指</span><span style="font-family: 宋体">每次执行的时间间隔</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">要停止的话，调用这个对象的</span><font face="Times New Roman">stop</font><span style="font-family: 宋体">方法就可以了</span><font face="Times New Roman"> a.stop()&nbsp;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">&nbsp;</font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">三</span>)Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>string.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">下面介绍</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">对</span><font face="Times New Roman">String</font><span style="font-family: 宋体">对象的扩展部分：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">这部分主要为</span><font face="Times New Roman">string</font><span style="font-family: 宋体">对象添加了几个很有用的方法</span><font face="Times New Roman">:</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">strip(): </font><span style="font-family: 宋体">去掉字符串两边的空白</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">"&nbsp;jj&nbsp;".strip()</font><span style="font-family: 宋体">返回</span><font face="Times New Roman">"jj"</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">stripTags()</font><span style="font-family: 宋体">：去掉字符串中的</span><font face="Times New Roman">html</font><span style="font-family: 宋体">标签</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">stripScripts(): </font><span style="font-family: 宋体">去掉字符串中的</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">代码段</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">extractScripts(): </font><span style="font-family: 宋体">返回字符串中的</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">代码，返回数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">evalScripts(): </font><span style="font-family: 宋体">执行字符串中的</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">代码</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">escapeHTML()</font><span style="font-family: 宋体">：将字符串中的</span><font face="Times New Roman">html</font><span style="font-family: 宋体">代码转换为可以直接显示的格式</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如将</span><font face="Times New Roman">&lt; </font><span style="font-family: 宋体">转化为</span><font face="Times New Roman"> &amp;lt; </font><span style="font-family: 宋体">，在</span><font face="Times New Roman">ie6</font><span style="font-family: 宋体">中有</span><font face="Times New Roman">bug</font><span style="font-family: 宋体">，执行这个操作返回的字符串，将多个连在一起的空白变成了一个，所以很多换行什么的都被去掉了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">unescapeHTML(): escapeHTML</font><span style="font-family: 宋体">的反向过程</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">truncate(length, truncation): </font><span style="font-family: 宋体">截断，例如</span><font face="Times New Roman">"abcdefghigkl".truncate(10)</font><span style="font-family: 宋体">返回</span><font face="Times New Roman">abcdefg</font><span style="font-family: 宋体">&#8230;</span><font face="Times New Roman">, truncation</font><span style="font-family: 宋体">默认为</span><font face="Times New Roman">"</font><span style="font-family: 宋体">&#8230;</span><font face="Times New Roman">" toQueryParams(separator)/parseQuery(separator)</font><span style="font-family: 宋体">：将一个</span><font face="Times New Roman">querystring</font><span style="font-family: 宋体">转化为一个</span><font face="Times New Roman">hash</font><span style="font-family: 宋体">表（其实是一个对象，在</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">中对象可以当成</span><font face="Times New Roman">hash</font><span style="font-family: 宋体">表来用，因为对象的属性或方法可以通过</span><font face="Times New Roman">object[propertyName]</font><span style="font-family: 宋体">来访问）</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">toArray(): return this.split('</font><span style="font-family: 宋体">&#8217;</span><font face="Times New Roman">), </font><span style="font-family: 宋体">转化为一个字符数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">camelize(): </font><span style="font-family: 宋体">将</span><font face="Times New Roman">background-color</font><span style="font-family: 宋体">的形式转化为</span><font face="Times New Roman">backgroundColor</font><span style="font-family: 宋体">形式，用在</span><font face="Times New Roman">style/css</font><span style="font-family: 宋体">中</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">capitalize(): </font><span style="font-family: 宋体">返回一个首字母大写的字符串</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inspect(useDoubleQuotes): </font><span style="font-family: 宋体">返回字符串的表示形式</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">"sdfj""sfa".inspect() </font><span style="font-family: 宋体">返回</span><span style="font-family: 宋体">&#8220;&#8217;</span><font face="Times New Roman">sdfj"sfa</font><span style="font-family: 宋体">&#8217;&#8221;</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">gsub(pattern, replacement)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">pattern</font><span style="font-family: 宋体">是一个正则表达式，</span><font face="Times New Roman">replacement</font><span style="font-family: 宋体">是一个函数</span><font face="Times New Roman">(</font><span style="font-family: 宋体">或者是一个</span><font face="Times New Roman">template</font><span style="font-family: 宋体">字符串</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，对于字符串中每个匹配</span><font face="Times New Roman">pattern</font><span style="font-family: 宋体">的部分使用</span><font face="Times New Roman">replacement</font><span style="font-family: 宋体">处理，然后将</span><font face="Times New Roman"> replacement</font><span style="font-family: 宋体">返回的值将原来匹配的部分替换掉，例如</span><font face="Times New Roman">"skdjfAsfdjkAdk".gsub(/A/,function(match) {return match[0].toLowerCase()}), </font><span style="font-family: 宋体">将字符串所有的</span><font face="Times New Roman">A</font><span style="font-family: 宋体">转化为</span><font face="Times New Roman">a, </font><span style="font-family: 宋体">注意</span><font face="Times New Roman">pattern</font><span style="font-family: 宋体">中不要添加</span><font face="Times New Roman">g</font><span style="font-family: 宋体">选项，因为</span><font face="Times New Roman">gsub</font><span style="font-family: 宋体">会递归的执行</span><font face="Times New Roman">match</font><span style="font-family: 宋体">方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">sub(pattern, replacement, count) </font><span style="font-family: 宋体">：</span><font face="Times New Roman">gsub</font><span style="font-family: 宋体">的另一种形式，不过可以设置执行的次数</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">scan(pattern, iterator): </font><span style="font-family: 宋体">跟</span><font face="Times New Roman">gsub</font><span style="font-family: 宋体">差不多，但是返回的是字符串本身，也就是说对于</span><font face="Times New Roman">pattern</font><span style="font-family: 宋体">中的每个匹配执行</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">，但是不返回替换的字符串</span><font face="Times New Roman">"skdjfAsfdjkAdk".gsub(/A/,function(){alert have a A</font><span style="font-family: 宋体">&#8217;</span><font face="Times New Roman">})</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">underscore(): 'borderBottomWidth&#8217;.underscore()&nbsp;-&gt; 'border_bottom_width&#8217;</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">dasherize(): 'Hello_World&#8217;.dasherize()&nbsp;-&gt; 'Hello-World&#8217;</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Template</font><span style="font-family: 宋体">模板类：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">使用方法：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">var template = new Template(replacement, pattern);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">template.evaluate(object) </font><span style="font-family: 宋体">有点像</span><font face="Times New Roman">php</font><span style="font-family: 宋体">中的模板，默认</span><font face="Times New Roman">(</font><span style="font-family: 宋体">没有提供</span><font face="Times New Roman">pattern)</font><span style="font-family: 宋体">将</span><font face="Times New Roman">{propertyName}</font><span style="font-family: 宋体">形式的东西替换了</span><font face="Times New Roman">object</font><span style="font-family: 宋体">的属性值</span></font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">四</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>Enumerable.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">是一个抽象对象（需要说明的是，</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">中并没有类的概念，所指的类也就是一个函数，继承一般指的是一个对象</span><font face="Times New Roman">(</font><span style="font-family: 宋体">父</span><font face="Times New Roman">)</font><span style="font-family: 宋体">将它的方法属性</span><font face="Times New Roman">copy(</font><span style="font-family: 宋体">通过</span><font face="Times New Roman">Object.extend, copy</font><span style="font-family: 宋体">的是引用</span><font face="Times New Roman">)</font><span style="font-family: 宋体">到子类</span><font face="Times New Roman">(</font><span style="font-family: 宋体">函数</span><font face="Times New Roman">)</font><span style="font-family: 宋体">的</span><font face="Times New Roman">prototype</font><span style="font-family: 宋体">属性</span><font face="Times New Roman">(</font><span style="font-family: 宋体">一个对象</span><font face="Times New Roman">)</font><span style="font-family: 宋体">中）</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">不能直接使用，它被很多枚举类型（</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">、</span><font face="Times New Roman">Array</font><span style="font-family: 宋体">、</span><font face="Times New Roman">Range</font><span style="font-family: 宋体">等）所继承，继承的类型都要实现一个</span><font face="Times New Roman">_each</font><span style="font-family: 宋体">方法，提供具体类型的枚举方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">为其他子类提供了如下的方法：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">each(iterator): iterator</font><span style="font-family: 宋体">是一个函数对象</span><font face="Times New Roman">, </font><span style="font-family: 宋体">这个方法调用具体类型的</span><font face="Times New Roman">_each</font><span style="font-family: 宋体">方法对自身包含的每个对象调用</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">，例如如果</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">具体指的是一个</span><font face="Times New Roman">Array</font><span style="font-family: 宋体">，</span><font face="Times New Roman">eg: var a=[2,3,4], </font><span style="font-family: 宋体">则</span><font face="Times New Roman">a.each(iterator)</font><span style="font-family: 宋体">方法将依次调用</span><font face="Times New Roman">iterator(2,0) ,iterator(3,1), iterator(4,3)</font><span style="font-family: 宋体">，其中第二个参数指的是索引。这个方法几乎在</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">中的每个方法中都要用到</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">eachSlice(number, iterator)</font><span style="font-family: 宋体">：将</span><font face="Times New Roman">Enumerable </font><span style="font-family: 宋体">类型对象每个每个按照</span><font face="Times New Roman">number</font><span style="font-family: 宋体">分开，例如</span><font face="Times New Roman">[1,2,3,4,5].eachSlice(3)=&gt;[[1,2,3],[4,5]], </font><span style="font-family: 宋体">没有提供</span><font face="Times New Roman">iterator, </font><span style="font-family: 宋体">则</span><font face="Times New Roman">iterator=Prototype.K: function(k){return k}</font><span style="font-family: 宋体">，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中的很多</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">默认值都是这个，或者是</span><font face="Times New Roman">Prototype.emptyFunction: function() {},</font><span style="font-family: 宋体">其实实际上返回的是</span><font face="Times New Roman">[iterator([1,2,3]),iterator([4,5])]</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">all(iterator): </font><span style="font-family: 宋体">对</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">类型中的每个值调用</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">，如果其中有一个返回</span><font face="Times New Roman">false</font><span style="font-family: 宋体">，则返回</span><font face="Times New Roman">false</font><span style="font-family: 宋体">，否则返回</span><font face="Times New Roman">true</font><span style="font-family: 宋体">，相当于判断是否每个值执行</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">都是</span><font face="Times New Roman">"true"</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">any(iterator): </font><span style="font-family: 宋体">跟</span><font face="Times New Roman">all</font><span style="font-family: 宋体">相反，判断是否每个值都是</span><font face="Times New Roman">"false"</font><span style="font-family: 宋体">（是否有一个值是</span><font face="Times New Roman">true</font><span style="font-family: 宋体">）</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">collect(iterator)/map: </font><span style="font-family: 宋体">对每个值调用</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">，将结果组成一个新的数组返回</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">detect(iterator)/find: </font><span style="font-family: 宋体">对每个值调用</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">，如果有一个不为</span><font face="Times New Roman">false</font><span style="font-family: 宋体">，则返回这个执行</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">后不为</span><font face="Times New Roman">false</font><span style="font-family: 宋体">的值</span><font face="Times New Roman">(</font><span style="font-family: 宋体">不是返回执行</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">后的值</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，相当于找出第一个真值</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">findAll(iterator)/select: </font><span style="font-family: 宋体">相当于</span><font face="Times New Roman">detect, </font><span style="font-family: 宋体">但是找出所有的真值，返回一个数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">grep(pattern, iterator)</font><span style="font-family: 宋体">：返回所以符合</span><font face="Times New Roman">pattern</font><span style="font-family: 宋体">的值，</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">提供的话，则返回执行</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">的值</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">include(object)/member: </font><span style="font-family: 宋体">数组中是否包含</span><font face="Times New Roman">object</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inGroupsOf(number, fillWith): eachSlice</font><span style="font-family: 宋体">的变异版本，按照</span><font face="Times New Roman">number</font><span style="font-family: 宋体">将对象分开，如果分开后的数组的最后一个值的</span><font face="Times New Roman">length</font><span style="font-family: 宋体">小于</span><font face="Times New Roman">number, </font><span style="font-family: 宋体">则用</span><font face="Times New Roman">fillwith</font><span style="font-family: 宋体">填充</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">[1,2,3,4,5].inGroupsOf(3)=&gt;[[1,2,3],[4,5,null]]</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inject(memo, iterator): </font><span style="font-family: 宋体">注入</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">invoke(method): </font><span style="font-family: 宋体">调用</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">max(iterator): </font><span style="font-family: 宋体">最大值</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">min(iterator): </font><span style="font-family: 宋体">最小值</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">partition(iterator): </font><span style="font-family: 宋体">分离</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">pluck(property): </font><span style="font-family: 宋体">采集</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">reject(iterator): </font><span style="font-family: 宋体">不合格的产品</span><font face="Times New Roman">, </font><span style="font-family: 宋体">于</span><font face="Times New Roman">findAll</font><span style="font-family: 宋体">相反</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">sortBy(iterator): </font><span style="font-family: 宋体">根据</span><font face="Times New Roman">iterator</font><span style="font-family: 宋体">排序，如果调用的对象是</span><font face="Times New Roman">Array</font><span style="font-family: 宋体">的话，直接调用内置的</span><font face="Times New Roman">sort(iterator)</font><span style="font-family: 宋体">就行了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">toArray()/entries: </font><span style="font-family: 宋体">将调用对象的每个值组成一个数组返回</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">zip(): </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">[2,3,4].zip([5,6,7])=&gt;[[2,5],[3,6],[4,7]], </font><span style="font-family: 宋体">如果最后一个参数类型为</span><font face="Times New Roman">function</font><span style="font-family: 宋体">，将返回</span><font face="Times New Roman">[iterator([2,5]),iterator([3,6]),iterator([4,7])],</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inspect(): Enumerable</font><span style="font-family: 宋体">对象的字符串表示</span></font></p>
 <img src ="http://www.blogjava.net/hummer008/aggbug/203707.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:37 <a href="http://www.blogjava.net/hummer008/articles/203707.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Prototype（1.5 rc2)使用指南（二） (转)</title><link>http://www.blogjava.net/hummer008/articles/203706.html</link><dc:creator>hummer</dc:creator><author>hummer</author><pubDate>Thu, 29 May 2008 01:36:00 GMT</pubDate><guid>http://www.blogjava.net/hummer008/articles/203706.html</guid><wfw:comment>http://www.blogjava.net/hummer008/comments/203706.html</wfw:comment><comments>http://www.blogjava.net/hummer008/articles/203706.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hummer008/comments/commentRss/203706.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hummer008/services/trackbacks/203706.html</trackback:ping><description><![CDATA[<div>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">五</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>array.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">$A = Array.from(iterable): </font><span style="font-family: 宋体">将</span><font face="Times New Roman">iterable</font><span style="font-family: 宋体">转化为数组，如果</span><font face="Times New Roman">iterable</font><span style="font-family: 宋体">定义了</span><font face="Times New Roman">toArray</font><span style="font-family: 宋体">方法，就调用这个方法，否则利用</span><font face="Times New Roman">iterable</font><span style="font-family: 宋体">的</span><font face="Times New Roman">length</font><span style="font-family: 宋体">属性进行枚举</span><font face="Times New Roman">, </font><span style="font-family: 宋体">如果</span><font face="Times New Roman">iterable</font><span style="font-family: 宋体">没有</span><font face="Times New Roman">length</font><span style="font-family: 宋体">属性的话就返回空数组</span><font face="Times New Roman">[]</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Array</font><span style="font-family: 宋体">对象除了扩展</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">对象的方法外，另外扩展了如下的几个方法，</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">注意以下方法除了</span><font face="Times New Roman">clear</font><span style="font-family: 宋体">外都不改变原来数组，而是返回一个新数组：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">clear(): </font><span style="font-family: 宋体">清除数组，利用</span><font face="Times New Roman">arr.length=0</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">first(): </font><span style="font-family: 宋体">返回第一个元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">last()</font><span style="font-family: 宋体">：返回最后一个元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">compact(): </font><span style="font-family: 宋体">去除数组中值为</span><font face="Times New Roman">null</font><span style="font-family: 宋体">或</span><font face="Times New Roman">undefined</font><span style="font-family: 宋体">的元素</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">flatten(): </font><span style="font-family: 宋体">将数组扁平化，例如</span><font face="Times New Roman">[3,4,[6,7]]</font><span style="font-family: 宋体">变为</span><font face="Times New Roman">[3,4,6,7]</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">without(): </font><span style="font-family: 宋体">去除指定的元素</span><font face="Times New Roman">, </font><span style="font-family: 宋体">可以指定多个值</span><font face="Times New Roman">, </font><span style="font-family: 宋体">例如</span><font face="Times New Roman">[4,56,7,8].without(4,7) </font><span style="font-family: 宋体">返回</span><font face="Times New Roman">[56</font><span style="font-family: 宋体">，</span><font face="Times New Roman">8]</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">indexOf(object): </font><span style="font-family: 宋体">返回指定的元素在数组中的索引，不包含则返回</span><font face="Times New Roman">-1</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">reverse(inline)</font><span style="font-family: 宋体">：</span><font face="Times New Roman">Array</font><span style="font-family: 宋体">内置函数</span><font face="Times New Roman">reverse</font><span style="font-family: 宋体">的增强，当</span><font face="Times New Roman">inline</font><span style="font-family: 宋体">为</span><font face="Times New Roman">true</font><span style="font-family: 宋体">时，跟内置的</span><font face="Times New Roman">reverse</font><span style="font-family: 宋体">函数效果一样，改变原数组的值，否则不改变原来的值</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">reduce(): </font><span style="font-family: 宋体">如果数组只有一个元素，则返回这个元素，否则返回数组本身</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">uniq(): </font><span style="font-family: 宋体">返回没有重复元素的数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">clone(): </font><span style="font-family: 宋体">返回一个跟数组相同的数组，</span><font face="Times New Roman">Array</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">toArray</font><span style="font-family: 宋体">方法覆盖了</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">toArray</font><span style="font-family: 宋体">方法，指向了这个方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inspect(): </font><span style="font-family: 宋体">跟数组的</span><font face="Times New Roman">toString</font><span style="font-family: 宋体">方法类似，返回对象的字符串表示，例如</span><font face="Times New Roman">[2,3].inspect() </font><span style="font-family: 宋体">返回</span><font face="Times New Roman"> "[2,3]" </font></font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">六</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>hash.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Hash</font><span style="font-family: 宋体">对象</span><font face="Times New Roman">(</font><span style="font-family: 宋体">关联数组</span><font face="Times New Roman">)</font><span style="font-family: 宋体">是</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">新建的一个对象，要创建一个</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">对象可以调用</span><font face="Times New Roman">$H(object)</font><span style="font-family: 宋体">方法，使用这个方法将生成一个基于</span><font face="Times New Roman"> object</font><span style="font-family: 宋体">对象的</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">对象，生成的</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">对象将</span><font face="Times New Roman">object</font><span style="font-family: 宋体">的属性名作为</span><font face="Times New Roman">key</font><span style="font-family: 宋体">，将</span><font face="Times New Roman">object</font><span style="font-family: 宋体">的属性值最为键值，因为</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">本身的特点</span><font face="Times New Roman">(</font><span style="font-family: 宋体">对象本身就是关联数组</span><font face="Times New Roman">) </font><span style="font-family: 宋体">，所以实现</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">也很简单，</span><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">只是</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">的关联数组</span><font face="Times New Roman">(</font><span style="font-family: 宋体">对象</span><font face="Times New Roman">)</font><span style="font-family: 宋体">而已</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">Hash</font><span style="font-family: 宋体">对象继承自</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">对象，所以也具有</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">对象的所有属性和方法，另外它具有以下的方法：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">keys(): </font><span style="font-family: 宋体">返回</span><font face="Times New Roman">hash</font><span style="font-family: 宋体">的键值数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">values(): </font><span style="font-family: 宋体">返回值得数组</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">merge(hash): </font><span style="font-family: 宋体">合并两个</span><font face="Times New Roman">hash</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">toQueryString(): </font><span style="font-family: 宋体">跟</span><font face="Times New Roman">string</font><span style="font-family: 宋体">的</span><font face="Times New Roman">toQueryParams</font><span style="font-family: 宋体">方法想法，将</span><font face="Times New Roman">hash</font><span style="font-family: 宋体">转化为一个</span><font face="Times New Roman">querystring, </font><span style="font-family: 宋体">会调用</span><font face="Times New Roman">encodeURIComponent</font><span style="font-family: 宋体">对键和值进行编码</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">inspect(): hash</font><span style="font-family: 宋体">的字符串表示</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">因为</span><font face="Times New Roman">hash</font><span style="font-family: 宋体">只是</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">的一个普通的对象而已，所以添加一个键值对使用：</span><font face="Times New Roman"> hash[key]=value</font><span style="font-family: 宋体">就可以了，删除一个键值对使用</span><font face="Times New Roman"> detele hash[key]</font><span style="font-family: 宋体">就可以了</span></font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">七</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>range.js</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Range</font><span style="font-family: 宋体">对象是一个继承自</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">的</span><font face="Times New Roman">"</font><span style="font-family: 宋体">范围</span><font face="Times New Roman">"</font><span style="font-family: 宋体">对象，你可以把它看成</span><font face="Times New Roman">[x,x+1,x+2,x+3</font><span style="font-family: 宋体">&#8230;&#8230;</span><font face="Times New Roman">x+n]</font><span style="font-family: 宋体">的数组看待，但是比这样的数组更节省存储空间，因为</span><font face="Times New Roman">range</font><span style="font-family: 宋体">对象只是保存</span><font face="Times New Roman">x</font><span style="font-family: 宋体">和</span><font face="Times New Roman">x+n</font><span style="font-family: 宋体">而已</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">要创建一个</span><font face="Times New Roman">Range</font><span style="font-family: 宋体">对象调用</span><font face="Times New Roman">$R(start, end, exclusive) </font><span style="font-family: 宋体">函数就可以了，</span><font face="Times New Roman">exclusive</font><span style="font-family: 宋体">指定是否包含</span><font face="Times New Roman">end</font><span style="font-family: 宋体">本身，如果没有指定或为</span><font face="Times New Roman">false</font><span style="font-family: 宋体">则包含</span><font face="Times New Roman">end</font><span style="font-family: 宋体">，否则不包含</span><font face="Times New Roman">,</font><span style="font-family: 宋体">你可以利用</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">中定义的方法来操作</span><font face="Times New Roman">range</font><span style="font-family: 宋体">对象，</span><font face="Times New Roman">range</font><span style="font-family: 宋体">对象只是实现了</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">对象需要的枚举逻辑</span><font face="Times New Roman">_each</font><span style="font-family: 宋体">和覆盖了</span><font face="Times New Roman">include</font><span style="font-family: 宋体">方法而已</span></font></p>
<h2 style="margin: 13pt 0cm"><font size="3">(<span style="font-family: 黑体">八</span>).Prototype<span style="font-family: 黑体">（</span>1.5 rc2)<span style="font-family: 黑体">使用指南之</span>ajax</font></h2>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Prototype</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">ajax.js</font><span style="font-family: 宋体">提供了一个非常好用的</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">框架，一般应用中简单的调用以下代码就可以了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">new Ajax.Request(</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp; url, {method: &#8220;get&#8221;,</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp; onSuccess: showFilter,</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp; onFailure: function(request){alert(&#8221;Server error!&#8221;)},</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp; onException: showError}</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;);</font></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">这个框架中提供了如下的对象和方法等：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax</font><span style="font-family: 宋体">对象：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">只有一个</span><font face="Times New Roman">getTransport</font><span style="font-family: 宋体">方法，返回一个</span><font face="Times New Roman">XMLHttpRequest</font><span style="font-family: 宋体">对象，另外有一个</span><font face="Times New Roman">activeRequestCount</font><span style="font-family: 宋体">属性，反映当前正在处理的</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">数量</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax.Responders</font><span style="font-family: 宋体">对象：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">继承自</span><font face="Times New Roman">Enumerable</font><span style="font-family: 宋体">，管理全局</span><font face="Times New Roman">Ajax</font><span style="font-family: 宋体">的请求，具有如下方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">register(responder)</font><span style="font-family: 宋体">：注册一个管理</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">请求的对象</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">unregister(responder)</font><span style="font-family: 宋体">：撤销一个管理</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">请求的对象</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">dispatch(callback, request, transport, json)</font><span style="font-family: 宋体">：触发注册的处理对象的方法</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">这个对象一般很少使用，系统中已经使用如下的代码注册了一个处理对象</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">Ajax.Responders.register({</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;onCreate: function() {</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp; Ajax.activeRequestCount++;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;},</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;onComplete: function() {</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;&nbsp;&nbsp; Ajax.activeRequestCount&#8211;;</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman"><font size="3">&nbsp;}</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">});</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax.Base</font><span style="font-family: 宋体">类：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax</font><span style="font-family: 宋体">的基类</span><font face="Times New Roman">, </font><span style="font-family: 宋体">只有一个方法</span><font face="Times New Roman">setOptions(options), </font><span style="font-family: 宋体">默认</span><font face="Times New Roman">request</font><span style="font-family: 宋体">参数如下，你可以在新建</span><font face="Times New Roman">Ajax.request</font><span style="font-family: 宋体">时指定：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'post&#8217;,</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">asynchronous: true,</font></p>
<p style="margin: 0cm 0cm 0pt"><font face="Times New Roman" size="3">contentType:&nbsp;'application/x-www-form-urlencoded&#8217;,</font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">encoding:&nbsp;&nbsp;&nbsp;&nbsp; </font><span style="font-family: 宋体">'</span><font face="Times New Roman">UTF-8</font><span style="font-family: 宋体">&#8242;</span><font face="Times New Roman">,</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax.Request</font><span style="font-family: 宋体">类：</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">ajax</font><span style="font-family: 宋体">主要的类，继承自</span><font face="Times New Roman">ajax.base</font><span style="font-family: 宋体">类，客户端使用</span><font face="Times New Roman"> new Ajax.Request(url,options) </font><span style="font-family: 宋体">调用，</span><font face="Times New Roman">options</font><span style="font-family: 宋体">是一个对象</span><font face="Times New Roman">(</font><span style="font-family: 宋体">关联数组</span><font face="Times New Roman">), </font><span style="font-family: 宋体">在</span><font face="Times New Roman">options</font><span style="font-family: 宋体">中可以指定</span><font face="Times New Roman">method</font><span style="font-family: 宋体">，</span><font face="Times New Roman">asynchronous</font><span style="font-family: 宋体">，</span><font face="Times New Roman">contentType</font><span style="font-family: 宋体">，</span><font face="Times New Roman">encoding</font><span style="font-family: 宋体">，</span><font face="Times New Roman">parameters</font><span style="font-family: 宋体">，</span><font face="Times New Roman"> postBody</font><span style="font-family: 宋体">，</span><font face="Times New Roman">username,password</font><span style="font-family: 宋体">等选项，其中</span><font face="Times New Roman">parameters</font><span style="font-family: 宋体">可以是字符传或者关联数组象，</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">另外在</span><font face="Times New Roman">options</font><span style="font-family: 宋体">中还可以通过</span><font face="Times New Roman">requestHeaders</font><span style="font-family: 宋体">指定</span><font face="Times New Roman">request heads</font><span style="font-family: 宋体">，其中</span><font face="Times New Roman">requestHeaders</font><span style="font-family: 宋体">可以是数组</span><font face="Times New Roman">(</font><span style="font-family: 宋体">例如</span><font face="Times New Roman">[</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">Connection</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">,</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">Close</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">,</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">aheadkey</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">,</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">aheadvalue</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">])</font><span style="font-family: 宋体">或一个关联数组；</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">options</font><span style="font-family: 宋体">中最重要的选项就是指定</span><font face="Times New Roman">ajax</font><span style="font-family: 宋体">的回调方法，可以定义</span><font face="Times New Roman">onComplete, onSuccess, onFailure, onException(</font><span style="font-family: 宋体">执行过程中发生异常调用的方法，主要为</span><font face="Times New Roman">onComplete, onSuccess, onFailure</font><span style="font-family: 宋体">等回调方法产生的</span><font face="Times New Roman">)</font><span style="font-family: 宋体">，甚至可以定义</span><font face="Times New Roman">on404,on503</font><span style="font-family: 宋体">这样的回调方法，它们的参数为</span><font face="Times New Roman">(transport, json),</font><span style="font-family: 宋体">其中</span><font face="Times New Roman">transport</font><span style="font-family: 宋体">为请求的</span><font face="Times New Roman">XMLHttpRequest</font><span style="font-family: 宋体">对象</span><font face="Times New Roman">, json</font><span style="font-family: 宋体">是</span><font face="Times New Roman">evalJSON</font><span style="font-family: 宋体">的结果</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">如果返回的是一个</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">文件</span><font face="Times New Roman">(</font><span style="font-family: 宋体">根据返回的</span><font face="Times New Roman">Content-type</font><span style="font-family: 宋体">头判断</span><font face="Times New Roman">)</font><span style="font-family: 宋体">将会执行</span><font face="Times New Roman">evalResponse</font><span style="font-family: 宋体">方法，另外</span><font face="Times New Roman">Ajax.Request</font><span style="font-family: 宋体">对象还有一个</span><font face="Times New Roman">evalJSON</font><span style="font-family: 宋体">方法，取得文件的时候就会执行</span></font></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"><font size="3">这个对象的方法列表如下：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">request(url) : </font><span style="font-family: 宋体">发送请求，</span><font face="Times New Roman">new</font><span style="font-family: 宋体">的时候就已经调用了，所以一般不需要使用</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">success(): </font><span style="font-family: 宋体">判断</span><font face="Times New Roman">request</font><span style="font-family: 宋体">是否成功了</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">getHeader(name)</font><span style="font-family: 宋体">：根据</span><font face="Times New Roman">name</font><span style="font-family: 宋体">得到</span><font face="Times New Roman">request head</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">evalJSON(): </font><span style="font-family: 宋体">执行</span><font face="Times New Roman">getHeader(</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">X-JSON</font><span style="font-family: 宋体">&#8221;</span><font face="Times New Roman">),</font><span style="font-family: 宋体">并返回结果</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">evalResponse(): </font><span style="font-family: 宋体">执行返回的</span><font face="Times New Roman">responseText</font><span style="font-family: 宋体">并返回</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax.Updater</font><span style="font-family: 宋体">类</span><font face="Times New Roman">:</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">继承自</span><font face="Times New Roman">Ajax.Request</font><span style="font-family: 宋体">，只是比</span><font face="Times New Roman">Ajax.Request</font><span style="font-family: 宋体">增加了更新</span><font face="Times New Roman">html</font><span style="font-family: 宋体">元素的功能，一般使用方法是</span><font face="Times New Roman">new Ajax.Updater(element, url, options), element</font><span style="font-family: 宋体">可以是一个元素，也可以是</span><font face="Times New Roman">{success:e1,failure:e2}</font><span style="font-family: 宋体">这种形式</span><font face="Times New Roman">,</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">默认情况下不会执行返回结果中的</span><font face="Times New Roman">javascript</font><span style="font-family: 宋体">，如果你先执行，你可以指定</span><font face="Times New Roman">options</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">evalScripts</font><span style="font-family: 宋体">为</span><font face="Times New Roman">true</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">默认情况下是替换指定元素的内容，如果你希望是添加，可以指定</span><font face="Times New Roman">options</font><span style="font-family: 宋体">的</span><font face="Times New Roman">insertion</font><span style="font-family: 宋体">参数</span><font face="Times New Roman">, insertion</font><span style="font-family: 宋体">是一个</span><font face="Times New Roman">Insertion.Before</font><span style="font-family: 宋体">、</span><font face="Times New Roman">Insertion.Top</font><span style="font-family: 宋体">或</span><font face="Times New Roman">Insertion.Bottom</font><span style="font-family: 宋体">、</span><font face="Times New Roman"> Insertion.After(</font><span style="font-family: 宋体">将在</span><font face="Times New Roman">dom.js</font><span style="font-family: 宋体">中介绍</span><font face="Times New Roman">)</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">Ajax.PeriodicalUpdater</font><span style="font-family: 宋体">类</span><font face="Times New Roman">:</font></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体">继承自</span><font face="Times New Roman">Ajax.Base</font><span style="font-family: 宋体">，周期性的更新一个</span><font face="Times New Roman">html</font><span style="font-family: 宋体">元素的内容，这个类会调用</span><font face="Times New Roman">Ajax.Updater</font><span style="font-family: 宋体">对</span><font face="Times New Roman">html</font><span style="font-family: 宋体">元素进行周期性的更新，使用方法为</span><font face="Times New Roman">new Ajax.PeriodicalUpdater(container, url, options), </font><span style="font-family: 宋体">参数跟</span><font face="Times New Roman">Ajax.Updater</font><span style="font-family: 宋体">差不多，其中</span><font face="Times New Roman">options</font><span style="font-family: 宋体">可以设置</span><font face="Times New Roman">frequency(</font><span style="font-family: 宋体">默认为</span><font face="Times New Roman">2)</font><span style="font-family: 宋体">，</span><font face="Times New Roman">decay</font><span style="font-family: 宋体">，</span><font face="Times New Roman">decay</font><span style="font-family: 宋体">指的是当请求的内容没有变化的时候，</span><font face="Times New Roman">frequency</font><span style="font-family: 宋体">需要延长的倍数，默认是</span><font face="Times New Roman">1</font><span style="font-family: 宋体">，例如如果</span><font face="Times New Roman">decay</font><span style="font-family: 宋体">设为</span><font face="Times New Roman">2</font><span style="font-family: 宋体">，</span><font face="Times New Roman">frequency</font><span style="font-family: 宋体">设为</span><font face="Times New Roman">3</font><span style="font-family: 宋体">而内容一直没有变化，则请求的时间依次会变为</span><font face="Times New Roman"> 3,6,12,24</font><span style="font-family: 宋体">等</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">start(): </font><span style="font-family: 宋体">开始更新</span><font face="Times New Roman">, </font><span style="font-family: 宋体">初始化的时候会自动调用</span></font></p>
<p style="margin: 0cm 0cm 0pt"><font size="3"><font face="Times New Roman">stop(): </font><span style="font-family: 宋体">停止更新</span></font></p>
</div>
 <img src ="http://www.blogjava.net/hummer008/aggbug/203706.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hummer008/" target="_blank">hummer</a> 2008-05-29 09:36 <a href="http://www.blogjava.net/hummer008/articles/203706.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>