Extract
1, $ F () function
Function:
Return of any form input control value, the parameters are the element id or the element itself
Example:
<script>
function test()
{
alert($F('userName'));
}
</script>
<input type="text" value="Joe Doe"><br>
<input type="button" value="Joe Doe"><br>
2, $ H ()
Function:
Put some objects into an enumerable and the United array similar Hash () object
Example:
<script>
function testHash()
{
var a = {first:10, second:20, third:30};
var h = $H(a); // 调用转换方法
alert(h.toQueryString()); //displays: first=10&second=20&third=30
}
</script>
<input type="text" value="Joe Doe"><br>
<input type="button" value="Joe Doe"><br>
3, Try.these ()
Function:
When you want to achieve in different ways to call until one of a successful
Example:
xmlNode.innerText available in IE, but in xmlNode.textContent available in FireFox, but the efficacy of two very
<script>
function getXmlNodeValue()
{
return Try.these(
function() {return xmlNode.innerText;},
function() {return xmlNode.textContent;}
);
}
</script>
<input type="text" value="Joe Doe"><br>
<input type="button" value="Joe Doe"><br>
4, $ ()
Function:
DOM in document.getElementById () method of shorthand, can be introduced to a number of id as a parameter then $ () returns an element with all the requirements of an Array object
Example:
<HTML>
<HEAD>
<TITLE> Test Page </TITLE>
<script src="prototype-1.3.1.js"></script>
<script>
function test1()
{
var d = $('myDiv');
alert(d.innerHTML);
}
function test2()
{
var divs = $('myDiv','myOtherDiv');
for(i=0; i<divs.length; i++)
{
alert(divs[i].innerHTML);
}
}
</script>
</HEAD>
<BODY>
<div>
<p>This is a paragraph</p>
</div>
<div>
<p>This is another paragraph</p>
</div>
<input type="button" value=Test1><br>
<input type="button" value=Test2><br>
</BODY>
</HTML>
5, $ A ()
Function:
Put parameters into an Array object, can easily put any of the enumerated list can be converted into or copy to an Array object. Recommend the use of a DOM Node Lists is put into an ordinary Array object, which carried out a more efficient traversal
Example:
<script>
function showOptions()
{
var someNodeList = $('lstEmployees').getElementsByTagName('option');
var nodes = $A(someNodeList);
nodes.each(function(node)
{
alert(node.nodeName + ': ' + node.innerHTML);
});
}
</script>
<select size="10" >
<option value="5">Buchanan, Steven</option>
<option value="8">Callahan, Laura</option>
<option value="1">Davolio, Nancy</option>
</select>
<input type="button" value="Show the options" >
6, $ R () 【required careful reading of the Methods】
Function:
new ObjectRange (lowBound, upperBound, excludeBounds) abbreviation
Example:
<script>
function demoDollar_R()
{
var range = $R(10, 20, false);
range.each(function(value, index)
{
alert(value);
});
}
</script>
<input type="button" value="Sample Count" >
7, Ajax object
Function:
Predefined objects, from the package creation, package Ajax logical categories
7.1 use Ajax.Request category
Assumptions through the url http: \ \ yourserver \ app \ get_sales? EmpID = 1234 & year = 1998 communicate with the server. Return the following XML response.
<?xml version="1.0" encoding="utf-8" ?> <ajax-response> <response type="object"> <monthly-sales> <employee-sales> <employee-id>1234</employee-id> <year-month>1998-01</year-month> <sales>$8,115.36</sales> </employee-sales> <employee-sales> <employee-id>1234</employee-id> <year-month>1998-02</year-month> <sales>$11,147.51</sales> </employee-sales> </monthly-sales> </response> </ajax-response>
Using Ajax.Request object and server communications, examples:
<script>
function searchSales()
{
var empID = $F('lstEmployees');
var y = $F('lstYears');
var url = 'http://yoursever/app/get_sales';
var pars = 'empID=' + empID + '&year=' + y;
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
onComplete: showResponse
});
}
function showResponse(originalRequest)
{
//put returned XML in the textarea
$('result').value = originalRequest.responseText;
}
</script>
<select size="10" onchange="searchSales()">
<option value="5">Buchanan, Steven</option>
<option value="8">Callahan, Laura</option>
<option value="1">Davolio, Nancy</option>
</select>
<select size="3" onchange="searchSales()">
<option selected="selected" value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
</select>
<br>
<textarea To be continued ... ...







