Ajax初始化下拉框数据

前端之家收集整理的这篇文章主要介绍了Ajax初始化下拉框数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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;
    
    }

猜你在找的Ajax相关文章