function DropDownList(url, domId, defaultValue) {
/// <summary>
/// ajax生成select
/// </summary>
/// <param name="url">数据请求路径</param>
/// <param name="domId">dom元素id</param>
/// <param name="defaultValue">默认选中值</param>
$.get(url, {}, function (msg) {
$("#" + domId).append("<option value='-1'>请选择</option>");
$(msg).each(function (i, e) {
$("#" + domId).append("<option value='" + e.Key + "'>" + e.Value + "</option>");
});
$("#" + domId).val(defaultValue);
});
}
<select id='test'></select>
使用如:
DropDownList("xxx","test",1)