Use a literal object to make a list

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.