1. 程式人生 > >jQuery select 全國城市三級聯動省市區(專案中修改頁面用到了)

jQuery select 全國城市三級聯動省市區(專案中修改頁面用到了)

jQuery select 全國城市三級聯動

在專案中修改頁面會用到,之前用$.filter()函式不行,換成$.each()就可以啦

附程式碼:

$(function () {
    _init_area();
     
    setTimeout(function () {
        changeArea();
    }, 200);
});
function changeArea() { //預設省var province = $("#areaProvince").val(); //預設市var city = $("#putArea").val
(); //預設區var area = $("#areaCounty").val(); $('#s_province option').each(function () { if ($(this).val() == province) { $(this).attr('selected', true); } });// $("#s_province option").filter('[value="' + province + '"]').attr('selected', true);
$('#s_province').trigger('change'); $('#s_city option').each(function () { if ($(this).val() == city) { $(this).attr('selected', true); } });// $("#s_city option").filter('[value="' + city + '"]').attr('selected', true);
$('#s_city').trigger('change'); $('#s_county option').each(function () { if ($(this).val() == area) { $(this).attr('selected', true); } });// $("#s_county option").filter('[value="' + area + '"]').attr('selected', true);}

最後附上js指令碼資源下載:

http://download.csdn.net/detail/qq_35624642/9705282