html
<input class="easyui-comboBox" id="ddl_yearTime" style="width: 100px;" editable="false" data-options=" method: 'get',panelHeight:'auto' " />
js
function LoadComBox(){ //加载年份 $('#ddl_yearTime').comboBox({ url:ActionURL + "loadComYear",valueField: 'id',textField: 'text',onSelect: function (ret) { yyear = ret.id; // yyear是全局变量 },onLoadSuccess: function () { //加载完成后,设置选中第一项 var val = $('#ddl_yearTime').comboBox("getData"); $("#ddl_yearTime").comboBox("setValue",yyear); } });
ashx
/// <summary> /// 初始化年份类型 /// </summary> /// <returns></returns> private string GetloadComYear() { string strRet = string.Empty; string strdata = "["; for (int i = DateTime.Now.Year; i <= DateTime.Now.Year+1; i++) { strdata += "{\"id\":\"" + i + "上半年\",\"text\":\"" + i + "上半年\"},"; if(i!=DateTime.Now.Year+1) strdata += "{\"id\":\"" + i + "下半年\",\"text\":\"" + i + "下半年\"},"; } strdata = strdata.TrimEnd(',') + "]"; strRet = strdata; return strRet; }