我有一个选择框:

<select id="translationOptions" name="translationOptions"></select>

我有一个js数组
var translationOptions = ["Egyptian Hieroglyphs", "Al Bhed (Final Fantasy X)", "Futurama"];

如何根据var translationOptions自动填充选择框?

最佳答案

$.each(translationOptions, function(key, value) {
    $('#mySelect')
         .append($("<option></option>")
         .attr("value",key)
         .text(value));
});

What is the best way to add options to a select from an array with jQuery?

08-19 06:55