Jquery $. each () Usage

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Html>
<Head>
<Title>
Use jquery each
</Title>
<Script type = 'text/javascript 'src = 'jquery-1.8.2.min.js'> </script>

<Script type = "text/javascript">
$ (Document). ready (function (){
// Traverse a one-dimensional array
Var arr1 = ["aaa", "bbb", "ccc"]; // use [] instead of {} for different time-varying values from the C Language {}
$. Each (arr1, function (I, val ){
Alert (I + "subscripts followed by values" + val );
});

// Traverse two-dimensional arrays
Var arr2 = [['A', 'aaa', 'aaa'], ['B', 'bbb', 'bbb'], ['C ', 'cc', 'ccc '];
$. Each (arr2, function (I, item ){
Alert (I + "subscripts followed by values" + item );
});
$. Each (arr2, function (I, item ){
$. Each (item, function (j, val ){
Alert (j + "The subscript is followed by the value" + val );
});
});

// Cyclically traverse the dom object
$. Each ($ ("input: hidden"), function (I, val ){
Alert (val); // It is a dom object.
Alert (I); // subscript 0 1 2
Alert (val. name );
Alert (val. value );
});
// The result is the same as above
$ ("Input: hidden"). each (function (I, val ){
Alert (I );
Alert (val );
Alert (val. name );
Alert (val. value );
});
});

</Script>
</Head>
<Body>
<Input name = "aaa" type = "hidden" value = "111"/>
<Input name = "bbb" type = "hidden" value = "222"/>
<Input name = "ccc" type = "hidden" value = "333"/>
<Input name = "ddd" type = "hidden" value = "444"/>
</Body>
</Html>

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.