The preferred Ajax framework for prototype. js lightweight web development (I)

Source: Internet
Author: User
    •  

Prototype. JS is a small JavaScript framework written by Sam Stephen enson (actually a function library), the Framework home page is: http://prototype.conio.net/

The following content is from the sources.

Lu's blog: www. lvjiyong. com

This article introduces several similar functions:$ (), $ F (), $ A, $ H,$ R.

$ ()EquivalentDocument. getelementbyid (),The intermediate parameter can be one ID or multiple IDs.

Example:

    test page        
  
  

welcome to the blog of Lu, I am a content 1 with the ID mydiv

welcome to the blog of Lu, I am a content 2 with the ID mytherdiv

Code "onclick =" test1 (); ">


Username:

$ ()Is more special, mainly used inNodelistsAttribute object. Use$ A ('object id ')The returned result is a set of array objects. Hahaha, this is an object. Let's take a look at the actual application example:

<SCRIPT>

Function showoptions (){
VaR somenodelist = $ ('lstemployees'). getelementsbytagname ('option ');
VaR nodes = $ A (somenodelist );

Nodes. Each (function (node ){
Alert (node. nodename + ':' + node. innerhtml );
});
}
</SCRIPT>

<Select id = "lstemployees" size = "3">
<Option value = "1"> lvjiyong.com </option>
<Option value = "2"> www. lvjiyong. com </option>
<Option value = "3"> Lu's blog </option>
</SELECT>

<Input type = "button" value = "display options" onclick = "showoptions ();">


Lvjiyong.comWww. lvjiyong. comLu's blog

$ H ()It is a hash object that I have not actually used. It seems that it is mainly used to convert objects into parameters for easy transmission (. NET serialization is simple and clear version ?), Let's take a look at the example:

<SCRIPT>
Function testhash ()
{
// Let's create the object to create an object
VaR A = {
First: 10,
Second: 20,
Third: 30
};

// Now transform it into a hash to convert to hash
VaR H =$ H ();
Alert (H. toquerystring (); // convert to a string. Hahaha can use ajax to upload the attributes of this object to the backend with displays: First = 10 & Second = 20 & third = 30
}

</SCRIPT>

Next we will talk about the last function today:$ R ()

The$ R ()Function is simply a short hand to writingNew objectrange (lowerbound, upperbound, excludebounds). Ha, this is definitely a very interesting function: Specify the upper and lower limits to return your ordered Range

Example:

<SCRIPT>
Function demodollar_r (){
VaR range =$ R (10, 20, false);
Range. Each (function (value, index ){
Alert (value );
});
}

</SCRIPT>

<Input type = "button" value = "$ r example" onclick = "demodollar_r ();">

The code word is really tired. I haven't modified it and translated it for a long time. Come here first.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.