我有一个看起来像这样的选择元素:
<select id="productId">
</select>
Run Code Online (Sandbox Code Playgroud)
我目前的jquery如下:
...
if (data.success) {
var items = [];
$.each(data.products, function(key, val) {
items.push('<options id="' + val + '">' + key + '</option>');
});
var options = items.join('');
$("#productId").html(options);
//$("#productId").val(options);
//$("#productId").append(options);
}
Run Code Online (Sandbox Code Playgroud)
我的所有尝试都不会使用我的新选项更新select标记.我错过了什么?
试试这个:
if (data.success) {
$.each(data.products, function(key, val) {
$('#productId').append('<option id="' + val + '">' + key + '</option>');
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |