Add HTML elements dynamically with JavaScript inside DIV with specific ID

前端 未结 2 570
清酒与你
清酒与你 2021-01-01 12:19

Ok, people, I need your help. I\'ve found some code here on Stackoverflow (can\'t find that link) which generate HTML code dynamically via JS. Here is code:

         


        
2条回答
  •  旧巷少年郎
    2021-01-01 13:05

    Step 1. Let's create a function to return us an ordered HTML listview. Note we are passing in an array of data:

    function createListView(spacecrafts){
        var listView=document.createElement('ol');
        for(var i=0;i

    Step 2. Then let's display our listview in your div:

    document.getElementById("displaySectionID").appendChild(createListView(myArr));
    

提交回复
热议问题