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;
}