我正在尝试使用 jQuery 多选插件填充下拉列表。当我使用具有硬编码值的简单下拉菜单时,它可以正常工作。但是,当我从数据库中获取记录以填充下拉列表时,记录不会显示在 IE 的下拉列表中(它在 Chrome 中工作正常)。
JavaScript
<script>
function Fill(U, F, D, C) {
$.ajax({ type: "POST",
url: U + '/' + F,
data: D,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
cache: false,
success: function (r) {
var i;
//$('#' + C + '').length = 0;
var myItem = r.d.split('#');
$('#' + C + '').empty();
for (i = 0; i < myItem.length; i = i + 2) {
$('#' + C).append(new Option('' + myItem[i + 1] + '','' + myItem[i] + ''));
}
}
});
}
$(document).ready(function () {
Fill('WebForm1.aspx', 'FillDepartmentDropdown', '{}', 'ddlDepartment');
$("#ddlDepartment").multiselect({
header: "Choose an Department!"
});
});
</script>
CS
[WebMethod]
public static string FillDepartmentDropdown()
{
string DataOutput = "";
DataSet ds;
Hashtable ObjParameters = new Hashtable();
BusinessLogicLayer ObjBusiness = new BusinessLogicLayer();
ds = ObjBusiness.SPDataSet(ObjParameters, "SelectAllDept");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow dr = ds.Tables[0].Rows[i];
DataOutput = DataOutput + "#" + dr["Department"].ToString() + "#" + dr["id"].ToString();
}
return DataOutput;
}
html
<select id="ddlDepartment" ><option>32</option> <option>3213</option><option>321</option></select>