Populate dropdown select with array using jQuery

后端 未结 8 1902
花落未央
花落未央 2020-11-29 08:07

I am trying to populate a dropdown select with an array using jQuery.

Here is my code:

        // Add the list of numbers to the drop down here
              


        
8条回答
  •  野性不改
    2020-11-29 08:44

    You can also do this:

    var list = $('#items')[0]; // HTMLSelectElement
    $.each(numbers, function(index, text) { 
        list.options[list.options.length] = new Option(index, text);
    }); 
    

提交回复
热议问题