Insert into HTML select tag options from a JSON

前端 未结 6 1788
甜味超标
甜味超标 2021-02-09 14:18

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:12

    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
    

提交回复
热议问题