Javascript 使用PageMethod更新下拉列表
我需要用从服务器端方法返回的对象列表填充DropDownList。因为这不会导致页面刷新,所以我使用PageMethods。调试时,我可以看到onSuccess函数正在被调用,但下拉列表没有填充。对象列表也正在从服务器端方法成功传递。我查不出哪里出了问题Javascript 使用PageMethod更新下拉列表,javascript,drop-down-menu,pagemethods,Javascript,Drop Down Menu,Pagemethods,我需要用从服务器端方法返回的对象列表填充DropDownList。因为这不会导致页面刷新,所以我使用PageMethods。调试时,我可以看到onSuccess函数正在被调用,但下拉列表没有填充。对象列表也正在从服务器端方法成功传递。我查不出哪里出了问题 function onsuccess(studList) { var ddl = document.getElementById('ddlStud'); var count =
function onsuccess(studList)
{
var ddl = document.getElementById('ddlStud');
var count = ddl.options.length;
while (ddl.options.length > 0)
{
ddl.options.remove(0);
}
for (var i = 0; i < studList.length; i++)
{
var option = document.createElement('<option value="' + studList[i].id + '">');
document.getElementById('ddlStud').options.add(option);
option.innerText = studList[i].StudName;
}
}
函数成功(studList)
{
var ddl=document.getElementById('ddlstund');
var count=ddl.options.length;
而(ddl.options.length>0)
{
ddl.options.remove(0);
}
对于(变量i=0;i
将for循环更新为:
for (var i = 0; i < studList.length; i++)
{
var option = document.createElement('option');
option.value= studList[i].id;
option.innerText = studList[i].StudName;
document.getElementById('ddlStud').options.add(option);
}
for(变量i=0;i