Several basic operations of jquery

Source: Internet
Author: User

Introduction of two functions (arrays) First

1.$.map (Array,function (Element,index));  

For each element in the array, call the function (Element,index) as shown above, and eventually return a new array. The original array does not change.

Case:

<script type= "Text/javascript" >

Double the value of the element with an index value greater than 3.

var arr=[2,3,4,5,6,7,8];

var Nwarr = $.map (arr,function (ele,index) {

Return index>3?ele*2:ele;

});

alert (Nwarr);

</script>

2.each(ARRAY,FN)

Iterate through the array, return false to exit the loop.

It is used primarily to iterate through an array, not to modify an array, or to have no problem with an ordinary array or a "key-value pair" array.

You can use this directly in the each function to represent the value of the current element.

Case:

var dic={"name": ' Xiao Ming ', ' age ': at all, ' gender ': ' Male '};

$.each (Dic,function (key,value) {

Alert (key+ '---' +value);

});

jquery objects, DOM objects

1. conversion

Dom objects if you want to invoke jquery, the method must first be converted to a jquery object.

2.Dom Objects  

Objects in the document tree are DOM objects.

3.jquery objects

When you wrap the DOM object, you get the jquery object.

4.dom→jquery

How do I convert a DOM object to a jquery object?

$ (spobj). Get (0). InnerHTML

$ (spobj) [0].innerhtml

5. Get the elements on the page directly from the jquery method

$ (' #id '), $ (' span '), $ ('. CLS ') 、......

The jquery object is called:. Text (), Val (), HTML (), CSS (' Color ', ' red ') 、......。 Most of jquery is a method with few attributes, because properties are difficult to chain-program. Getting the value, setting the value is the same method that is used, the parameter represents the set value, and no parameter represents the value.

6. which do not need to go to jquery objects

The array itself is not a DOM object. There is no conversion between the jquery objects. Using jquery statements you can use arrays directly, like $.each () or $.map ();

Add: The return value obtained by document.getElementsByTagName () or Document.getelementsbyname () is an array-like value, but not an array, with no array-specific methods.

parseint () \array These are not required to be converted.

Several basic operations of jquery

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.