js dynamically adds example code for a list of circled numbers

js dynamically adds example code for a list of circled numbers

1. Add the ul tag in the body first

<!-- Unordered list -->
<ul id="list">
	
</ul>

2. Get the tag with id equal to list through js, define an empty string to connect the added tags, and display them

The js code shown in the figure shows the circle numbers with different colors for the first three and the same colors for the remaining circles.

function autoAddList(){
  var oUl = document.getElementById('list');
  // var arr = ['Hunan', 'Guangxi', 'Xinjiang', 'Shanghai']
  var str = "";
  for (let i = 1; i < 13; i++) {
    if (i == 1) {
      str += '<li><a style="color: white"><span id="listOne" style="background-color: rgb(187, 7, 7)">' + i + '</span></a></li>' + '<br>';
    }else if (i == 2) {
      str += '<li><span style="background-color: #ffad33">' + i + '</span></li>' + '<br>';
    }else if (i == 3) {
      str += '<li><span style="background-color: green">' + i + '</span></li>' + '<br>';
    }else{
      str += '<li><span style="background-color: #339cff">' + i + '</span></li>' + '<br>';
    }    
  }
  oUl.innerHTML = str;
}

3.css style modification

/*Set the list style*/
ul{
  list-style-type: none;
}

list-style-type: none means no logo, and the attributes can also be hollow circles, solid squares, numbers, etc.

To arrange the serial numbers neatly, you need to set the span style

/*Set as inline block element*/
li span{
	display:inline-block;
}

The effect is shown in the figure below

insert image description here

This is the end of this article about how to dynamically add a circled number list with js. For more relevant content about how to dynamically add a circled number list with js, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JavaScript array, JSON object to achieve dynamic addition, modification, deletion function example
  • JS clicks to dynamically add tags and delete specified tags
  • An example of how to add HTML tags dynamically using JS
  • JS implementation example of adding event functions to dynamically added elements [based on event delegation]
  • How to add serial numbers to AngularJS tables
  • JavaScript automatically adds a serial number in front of the table

<<:  How to use the Linux more command in Linux common commands

>>:  Detailed explanation of MySql 5.7.17 free installation configuration tutorial

Recommend

Disable input text box input implementation properties

Today I want to summarize several very useful HTML...

This article will show you how JavaScript garbage collection works

Table of contents 1. Overview 2. Memory Managemen...

Control the light switch with js

Use js to control the light switch for your refer...

C# implements MySQL command line backup and recovery

There are many tools available for backing up MyS...

CentOS7 installation GUI interface and remote connection implementation

Use the browser (webdriver)-based selenium techno...

How does MySQL implement ACID transactions?

Preface Recently, during an interview, I was aske...

MySQL 8.0.11 Community Green Edition Installation Steps Diagram for Windows

In this tutorial, we use the latest MySQL communi...

Understanding of web design layout

<br />A contradiction arises. In small works...

Embed codes for several older players

The players we see on the web pages are nothing m...

Vue implements multiple ideas for theme switching

Table of contents Dynamically change themes The f...

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being a...

jQuery achieves the effect of advertisement scrolling up and down

This article shares the specific code of jQuery t...