Personally, I prefer this syntax for appending options:(就个人而言,我更喜欢以下语法来附加选项:)
$('#mySelect').append($('<option>', {
value: 1,
text: 'My option'
}));
If you're adding options from a collection of items, you can do the following:(如果要从一组项目中添加选项,则可以执行以下操作:)
$.each(items, function (i, item) {
$('#mySelect').append($('<option>', {
value: item.value,
text : item.text
}));
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…