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