我正在试图从我的数据库中填充项目的选择列表。我已经确认(使用“alert()”框)jquery .getJSON函数正在获取正确的数据,但是选择列表仍然没有填充。为什么我的选择列表没有填充?
var selectBox = document.createElement("select");
$.getJSON('optionGrabber.php', function(data) {
$.each(data, function(key, dbValue) {
var option = document.createElement("option");
option.setAttribute("value",dbValue);
selectBox.appendChild(option);
});
});
myDiv.appendChild(selectBox);
就像我说的,当我粘贴一个“alert(dbValue);”紧随“.each”语句之后,我在警报弹出窗口中获得正确的数据。
你用萤火虫检查了你的代码吗?你有什么错误吗? – Farshad 2014-08-29 20:43:17
http://stackoverflow.com/questions/740195/adding-options-to-a-select-using-jquery-javascript – Aguardientico 2014-08-29 20:43:41
@Farshad在Firebug中没有错误。 – Brian 2014-08-29 20:44:10