Home >Web Front-end >JS Tutorial >Use each in jQuery to process json data_jquery
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'); } });
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"} ]
If you want to use jquery to operate on this data, use $.each:
$.each(data, function(i, item) { alert(item.PageName); });
I personally tested it and it works.
The above is the entire content of this article, I hope you all like it.