Before I've talked about the back of the table returns JSON data to the foreground and traverses the JSON data in the foreground.
Here, directly in JS to create JSON data, and then traverse the use of ~
The creation code is as follows: (a JSON object is created)
var yearselect = {};
var year = 2014;
var dateoption;
for (var i = year; I < year + i++) {
dateoption = {' Year ': I, ' Month ': i-year+1};
/alert (dateoption.year)
yearselect[i] = dateoption;
}
Here is the creation of a JSON object that includes the year and month data.
Why I created the JSON object is because I'm familiar with the JSON object. The back of the PHP backend is also a JSON object.
JSON object has no length attribute ~ ~
So traverse the words to:
for (var key in Yearselect) {
alert (Yearselect[key].) year);
Alert (Yearselect[key). Month);
}
So it's OK.
Keep in mind that you have to distinguish between the objects and arrays of JSON, or it's always undenfined.