The literal object is a data transfer format, and we get a set of literal objects that are contained in an array, how do we apply it to dynamic creation? For example, give me a literal object: To do a show online number of programs, such as the current game ah, chat software Ah, can show the number of people online.
The subject part of it is:
So many users, we generally use a list form, if you write a static page, then we will continue in the class named module re-write, but this display number is at any time to become, generally from the database at any time to take data, so to write dynamic, in fact, dynamic steps and static have similar, we first create a UL label , and then create a Li, we usually use document.createelement () this to create dynamic elements, but here it seems troublesome. We should use inner. HTML is more convenient than this. Here are the programs I wrote myself:
The approximate steps are divided into these sections:
1: First create the UL label.
2: I built an empty array, here some people feel that there is no need to build an array, direct string concatenation, but the character designators has a feature is immutable, so directly take the word designators to do low efficiency, it is best to put in the array, and finally into a string.
3: Loop This array of literal objects, put each literal object in an Li tag and then assign to a variable, it is noted that the format of the format is more convenient, because the label has double quotation marks, all the tags outside with a single quotation mark, a single quotation mark in a label, the first direct return to the output, It will generate a single quote and a plus sign on the next line, you can just copy the tag in, loop it, and then add each variable that is assigned the LI tag to an empty array.
4: Finally, the number is assembled into a string and then assigned to the UL can be
Use a literal object to make a list