Home > Web Front-end > JS Tutorial > Use each in jQuery to process json data_jquery

Use each in jQuery to process json data_jquery

WBOY
Release: 2016-05-16 16:02:43
Original
1049 people have browsed it

eg: When the corresponding value of the passed-in ID is true, add a class named focus to the corresponding ID tag, such as:

var obj = { id01:'true', id02:'flase', id03:'true'};

$.each(obj,function(key,val){ 
   if(val == 'true'){ 
      $('#' + key).addClass('focus'); 
    } 
});

Copy after login

Result: A class tag will be added to the tags with IDs id01 and id03;

eg2:

The json data is as follows:

[ 
{"Id": 10004, "PageName": "club"}, 
{"Id": 10040, "PageName": "qaz"}, 
{"Id": 10059, "PageName": "beauty"}
]
Copy after login

If you want to use jquery to operate on this data, use $.each:

$.each(data, function(i, item) {
  alert(item.PageName);
});
Copy after login

I personally tested it and it works.

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template