1. 程式人生 > >easyui combobox下拉框省市縣三級聯動(從資料庫獲取資料)

easyui combobox下拉框省市縣三級聯動(從資料庫獲取資料)

//combobox的onLoadSuccess,onChange,onSelect事件   

省:<input id="province" style="width: 110px;" />

市:<input id="city" style="width: 110px;"/>

縣區:<input id="county" style="width: 110px;" />

$(document).ready(function(){

        //行政區域碼
        var re = $ht.form.ajaxS(請求地址,null,"json");
        if(re =="noRight"){
           return;
        }
        var list = new Array();
        list.push({ "id":"-1", "name": "全部" });
        if(re.list!=null&&re.list!='null'){
               list.push.apply(list,re.list);
        }
        $('#province').combobox({   
            data:list,
            editable:false, //不可編輯狀態  
            cache: false,  
           // panelHeight: 'auto',//自動高度適合  
            valueField:'id',     
            textField:'name',
            onLoadSuccess:function(){
                $('#province').combobox('select', list[0].id);
            }
        });
        $("#province").combobox({
            onSelect
:function(n,o){
                var province = $('#province').combobox('getValue');
                var data={id:province};
                var re = $ht.form.ajaxS(請求地址,data,"json");
                if(re =="noRight"){
                   return;
                }
                var list = new Array();
                list.push({ "id":"-1", "name": "全部" });
                if(re.list!=null&&re.list!='null'){
                       list.push.apply(list,re.list);
                }
                $('#city').combobox({   
                    data:list,
                    editable:false, //不可編輯狀態  
                    cache: false,  
                   // panelHeight: 'auto',//自動高度適合  
                    valueField:'id',     
                    textField:'name',
                    onLoadSuccess
:function(){
                        $('#city').combobox('select', list[0].id);
                    }
                });
                cityfun();
            }
        });
        function cityfun(){
            $("#city").combobox({
                onChange:function(n,o){
                    var city = $('#city').combobox('getValue');
                    var data={id:city};
                    var re = $ht.form.ajaxS(請求地址,data,"json");
                    if(re =="noRight"){
                       return;
                    }
                    var list = new Array();
                    list.push({ "id":"-1", "name": "全部" });
                    if(re.list!=null&&re.list!='null'){
                           list.push.apply(list,re.list);
                    }
                    $('#county').combobox({   
                        data:list,
                        editable:false, //不可編輯狀態  
                        cache: false,  
                        //panelHeight: 'auto',//自動高度適合  
                        valueField:'id',     
                        textField:'name'
                    });
                    $('#county').combobox('select', list[0].id);
                }
            });
        }

    });