【发布时间】:2014-01-17 12:48:32
【问题描述】:
我正在使用此方法将值和文本添加到选项中,但我还需要添加 selected 属性。我怎样才能做到这一点?这是我的方法……:
$.each(items, function (i, item) {
$('#mySelect').append($('<option>', {
value: item.value,
text : item.text
// is it possible to add here something like this: select: "selected"
}));
});
【问题讨论】:
-
我正在使用来自 Jquery 插件的 select2