Insert into HTML select tag options from a JSON

前端 未结 6 988
南方客
南方客 2021-02-09 14:32

So, here\'s the deal: I have a JSON object saved in my web App at localStorage. This JSON is being saved as a string, with JSON.stringify, inside one of my function

6条回答
  •  执笔经年
    2021-02-09 15:11

    As you are starting you can learn more of JavaScript from w3schools. There is an DOM object called Element that you can use to add an option into select. You just need to do something like:

    var el = document.getElementById('mySelectID'); //Get the select element
    var opt = document.createElement('option'); //Create option element
    opt.innerHTML = "it works!"; //Add a value to the option
    
    el.appendChild(opt); //Add the option to the select element
    

提交回复
热议问题