JQuery universal global Traversal method $. each () usage example, jquery. each
1. jQuery universal global Traversal method $. each () Usage
2. test. json file code:
3. html code
4. 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">