Home > front end >  Js implementation will cycle shows the JSON array in different div
Js implementation will cycle shows the JSON array in different div

Time:10-04

Read the json array using ajax from the background, and an array of multiple data, different fields of each array into the corresponding div,
The code I wrote as follows, don't know what's the problem, always show don't come out? A great god, please give directions!!!!!
Var reobj=[
{" content ":" top-up CARDS, "
"Time" : "17-09-08"
},
{" content ":" millet hand ring, "
"Time" : "17-03-12"
},
{" content ":" IPTV, "
"Time" : "18-01-02"
}
];
The function fu (arr) {

Var STR="";
For (I=0, len=arr. Length; iSTR +='& lt; Div & gt; ';
STR +='& lt; Div & gt; '+ arr [I] content +' & lt;/div> ';
STR +='& lt; Div & gt; '+ arr [I] time +' & lt;/div> ';
STR +='& lt;/div> ';
}
}

Document. GetElementById (" box "). The innerHTML=fu (reobj);
</script>

CodePudding user response:

Fu function finally add:
Return the STR;

CodePudding user response:

The function fu (arr) {

Var STR="";
For (I=0, len=arr. Length; iSTR +='& lt; Div & gt; ';
STR +='& lt; Div & gt; '+ arr [I] content +' & lt;/div> ';
STR +='& lt; Div & gt; '+ arr [I] time +' & lt;/div> ';
STR +='& lt;/div> ';
}
return STR.
}

CodePudding user response:

 
The function fu (arr) {
Var STR="";
for(i=0; iSTR +='& lt; Div & gt; ';
STR +='& lt; Div & gt; '+ arr [I] content +' & lt;/div> ';
STR +='& lt; Div & gt; '+ arr [I] time +' & lt;/div> ';
STR +='& lt;/div> ';
Return the STR;//must add the ah, the document. The getElementById (" box "). The innerHTML=fu (reobj); The return value,
}

CodePudding user response:

STR in a function, the scope is only in this way, you can remove the var in front of, thus become a global variable, can call, or in your method returns a STR

CodePudding user response:


 function fu (arr) {
Var STR="";
for(i=0; iSTR +='& lt; Div & gt; ';
STR +='& lt; Div & gt; '+ arr [I] content +' & lt;/div> ';
STR +='& lt; Div & gt; '+ arr [I] time +' & lt;/div> ';
STR +='& lt;/div> ';
}
Return the STR;//which have inside the for loop return ah, 3 floor of brother die


Which have inside the for loop return ah, 3 floor of brother die
Which have inside the for loop return ah, 3 floor of brother die
Which have inside the for loop return ah, 3/f brother die
  • Related