我需要从json填充下拉列表,我无法从html页面中选择ddl:
<asp:DropDownList ID="ddlPopUp" runat="server" /> //HTML
//JaveScript 1 - returns empty ddl
ar DdlPopUp = "<%=ddlPopUp.ClientID %>";
function fillDDL(data) {
var obj = $.parseJSON(data.Data);
var myList = "";
for (var i = 0; i < obj.length; i++) {
myList += "<option>"+ obj[i] +"</option>";
}
DdlPopUp.html(myList);
}
//JaveScript 2 - dll always null
function fillDDL(data) {
var obj = $.parseJSON(data.Data);
var dll = document.getElementById('ddlPopUp');
for (var i = 0; i < obj.length; i++) {
dll.appendChild(obj[i]);
}
}
为什么它不起作用?该怎么办?
答案 0 :(得分:0)
要使用jQuery访问客户端的DDL,您需要执行以下操作:
var DdlPopUp = $('#<%=ddlPopUp.ClientID %>');