Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<com:TContent ID="body" >
2
 
3
<h1 id="6601">Developer Notes for prototype.js</h1>
4
This guide is based on the <a href="http://www.sergiopereira.com/articles/prototype.js.html">
5
Developer Notes for prototype.js</a> by Sergio Pereira.
6
 
7
<h2 id="6603">What is that?</h2>
8
<p id="830726" class="block-content">
9
In case you haven't already used it, <a href="http://prototype.conio.net">prototype.js</a> is a
10
    JavaScript library written by <a href="http://www.conio.net">Sam Stephenson</a>.
11
    This amazingly well thought and well written piece of <b>standards-compliant</b> code takes a lot of
12
    the burden associated with creating rich, highly interactive web pages that characterize the Web 2.0 off your back.
13
</p>
14
 
15
<p id="830727" class="block-content">
16
    If you tried to use this library recently, you probably noticed that documentation is not one
17
    of its strongest points. As many other developers before me, I got my head around prototype.js by
18
    reading the source code and experimenting with it. I thought it would be nice to take notes while
19
    I learned and share with everybody else.
20
</p>
21
<p id="830728" class="block-content">
22
    As you read the examples and the reference, developers familiar with the Ruby
23
    programming language will notice an intentional similarity between Ruby's
24
    built-in classes and many of the extensions implemented by this library.
25
</p>
26
 
27
 
28
<h2 id="6604">Using the <tt>$()</tt> function</h2>
29
<p id="830729" class="block-content">
30
    The <tt>$()</tt> function is a handy shortcut to the all-too-frequent <tt>document.getElementById()</tt> function
31
    of the DOM. Like the DOM function, this one returns the element that has the id passed as an argument.
32
</p>
33
 
34
<p id="830730" class="block-content">
35
    Unlike the DOM function, though, this one goes further. You can pass more than one id and
36
    <tt>$()</tt> will return an <tt>Array</tt> object with
37
    all the requested elements. The example below should illustrate this.
38
</p>
39
<com:TTextHighlighter Language="javascript" CssClass="source block-content" id="code_830252">
40
&lt;com:TClientScript UsingClientScripts="prado" /&gt;
41
<div id="myDiv">
42
    <p id="830731" class="block-content">This is a paragraph</p>
43
</div>
44
 
45
<div id="myOtherDiv">
46
    <p id="830732" class="block-content">This is another paragraph</p>
47
</div>
48
 
49
<input type="button" value=Test1 onclick="test1();" />
50
<input type="button" value=Test2 onclick="test2();" />
51
 
52
<script type="text/javascript">
53
/*<![CDATA[*/
54
function test1()
55
{
56
    var d = $('myDiv');
57
    alert(d.innerHTML);
58
}
59
 
60
function test2()
61
{
62
    var divs = $('myDiv','myOtherDiv');
63
    for(i=0; i<divs.length; i++)
64
    {
65
        alert(divs[i].innerHTML);
66
    }
67
}
68
/*]]>*/
69
</script>
70
</com:TTextHighlighter>
71
<p id="830733" class="block-content">
72
    Another nice thing about this function is that you can pass either the <tt>id</tt> string or the element object itself,
73
    which makes this function very useful when creating other functions that can also take either form of argument.
74
</p>
75
 
76
<h2 id="6605">Using the <tt>$F()</tt> function</h2>
77
 
78
<p id="830734" class="block-content">
79
    The <tt>$F()</tt> function is a another welcome shortcut. It returns the value of any field input control,
80
    like text boxes or drop-down lists. The function can take as argument either the element <tt>id</tt> or the element object itself.
81
</p>
82
<com:TTextHighlighter Language="javascript" CssClass="source block-content" id="code_830253">
83
<input type="text" id="userName" value="Joe Doe" />
84
<input type="button" value=Test3 onclick="test3();" />
85
 
86
<script type="text/javascript">
87
/*<![CDATA[*/
88
function test3()
89
{
90
    alert($F('userName'));
91
}
92
/*]]>*/
93
</script>
94
</com:TTextHighlighter>
95
 
96
<div class="last-modified">$Id: Scripts1.page 1650 2007-01-24 06:55:32Z wei $</div></com:TContent>