2012-02-10 6 views

答えて

2

が追加されました:

$(document).ready(function() { 
    $('#myDropdown').empty(); // empty the dropdown (if necessarry) 
    $(accounts).each(function(iIndex, sElement) { 
     $('#myDropdown').append('<option>' + sElement + '</option>'); 
    }); 
}); 

this exampleを参照してください。

+0

ありがとうございます。 – Developer

0
var html = ''; 
jQuery.each(accounts, function(i , item) { 
    html += '<option value="'+item+'">'+item+'</option>'; 
} 
jQuery('#dropdown').append(html); 

技術的には、この変形は、我々は一度だけのリソースを大量に消費.append()を呼び出すため、高速です。しかし、一度あなたが100以上のアイテムを追加しようとすると、あなたは本当に違いを感じるだけです。