【发布时间】:2015-11-02 04:22:30
【问题描述】:
对于我的一生,我不知道为什么这不起作用 - 我尝试了多种方法来尝试将 JSON 数据插入到 <option> 代码中,每次它不起作用 - 它仅输出 HTML 文本,而不是在 <select> 下拉列表中
$.getJSON( "group.asp", function( data ) {
$('#msgBox').html($('#msgBox').html() + '<div class="table-row"><div class="table-col-l">Name:</div><div class="table-col-r"><select id="name1"><option>SELECT</option>')
$(data).each(function(index, element) {
console.log(element)
$('#msgBox').html($('#msgBox').html() + '<option>'+element.name+'</option>');
});
$('#msgBox').html($('#msgBox').html() + '</select></div></div>')
})
我尝试将它创建为一个单独的变量,插入到 .each 函数之后,但这也不起作用。
【问题讨论】:
标签: jquery arrays forms select