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
var numbers[] = { 1, 2, 3, 4, 5};
$.each(numbers, function(val, text) {
$('#items').append(
$('<option></option>').val(val).html(text)
);
// END
But I'm getting an error. The each function is something I am got off this website.
Is it bombing out because I'm using a one-dimensional array? I want both the option and the text to be the same.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…