JQuery universal global Traversal method $. each () usage example, jquery. each

Source: Internet
Author: User

JQuery universal global Traversal method $. each () usage example, jquery. each

This example describes the general global Traversal method $. each () in jQuery. We will share this with you for your reference. The details are as follows:

1. test. json file code:

[{"Username": "zhangsan", "content": "sofa. "},{" username ":" Li Si "," content ":" bench. "},{" username ":" Wang Wu "," content ":" floor. "}]

2.html code:

<P> <input type = "button" id = "send" value = "LOAD"/> </p> <div class = "comment"> existing comments: </div> <div id = "resText"> </div>

3. jQuery code:

<Script src = "jquery-1.3.1.js" type = "text/javascript"> </script> <script type = "text/javascript">/* 1. $. each () is a common Traversal method of jquery. It can be used to traverse objects and arrays. $. the each () function is different from the each () method of the jquery object. It is a global function that does not operate the jquery object, but uses an array or object as the first parameter, use a callback function as the second parameter. The callback function has two parameters: the first parameter is the index of the object member or array, and the second parameter is the corresponding variable or content */$ (function () {$ ('# send '). click (function () {$. getJSON ('test. json', function (data) {$ ('# resText '). empty (); var html = ''; $. each (data, function (commentIndex, comment) {html + = '<div class = "comment"> 

Related Article

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.