//省市县地址联动dwr /** * 1. * 页面上引用 dwr文件和当前js文件 * * * 2.加载时调用下面 * * 3. * 省 * * 4. * 市 * * 5. * 县 * * */ /** * 控件ID 初使化页面时调用 * @param provObj */ function onProviceLoad(provObj,cityObj,countyObj,defaultProv,defaultCity,defaultCounty,type) { var obj_ProSend = document.getElementById(provObj); // var obj_ProReceive = // document.getElementById("model.shipment.receiveProvince"); //DWREngine.setAsync(true); //是否是寄件人的 if(type == 'send'){ AddressAuto.getLimitPrivince(function(datas) { DWRUtil.removeAllOptions(obj_ProSend); DWRUtil.addOptions(obj_ProSend, { '' : '--请选择--' }); DWRUtil.addOptions(obj_ProSend, datas); }); }else{ AddressAuto.getPrivince(function(datas) { DWRUtil.removeAllOptions(obj_ProSend); DWRUtil.addOptions(obj_ProSend, { '' : '--请选择--' }); DWRUtil.addOptions(obj_ProSend, datas); }); } if(defaultProv!=null&&defaultProv!=''){ setSelectDefault(provObj,defaultProv); if(defaultCity!=null&&defaultCity!=''){ onProviceChange(provObj, cityObj, countyObj,defaultCity,defaultCounty); } } } /** * 当省onChange时调用 * @param provObj 省控件ID * @param cityObj 省控件ID * @param countyObj 省控件ID */ function onProviceChange(provObj, cityObj, countyObj,defaultCity,defaultCounty) { //alert("test"); // 省变化时把县清空,并设置为不可用; var obj_County = document.getElementById(countyObj); DWRUtil.removeAllOptions(obj_County); DWRUtil.addOptions(obj_County, {'' : '--请选择--'}); obj_County.disabled = true; var obj_ProSend = document.getElementById(provObj); var obj_CitySend = document.getElementById(cityObj); var pro_Index = obj_ProSend.selectedIndex; var pro_Value = obj_ProSend.options[pro_Index].value;// 省所选择择的值 // alert("value"+pro_Value); //housh 省变化时先把市清空,并设置为不可用; DWRUtil.removeAllOptions(obj_CitySend); DWRUtil.addOptions(obj_CitySend, {'' : '--请选择--'}); obj_CitySend.disabled = true; AddressAuto.getCityByProv(pro_Value, function(datas) { // DWRUtil.removeAllOptions(obj_CitySend); // DWRUtil.addOptions(obj_CitySend, { // '' : '--请选择--' // }); //数据返回时设置为可用; obj_CitySend.disabled = false; DWRUtil.addOptions(obj_CitySend, datas); }); if(defaultCity!=null&&defaultCity!=''){ setSelectDefault(cityObj,defaultCity); if(defaultCounty!=null&&defaultCounty!=''){ onCityChange(cityObj, countyObj,defaultCounty); } } } /** * 当市onChange 时调用 * @param CityObj 市控件ID * @param CountyObj 县控件ID */ function onCityChange(CityObj, CountyObj,defaultCounty) { var obj_CitySend = document.getElementById(CityObj); var obj_CountySend = document.getElementById(CountyObj); var pro_Index = obj_CitySend.selectedIndex; var pro_Value = obj_CitySend.options[pro_Index].value;// 市所选择择的值 // alert("City value:"+pro_Value); //housh 市变化时先把区县清空 DWRUtil.removeAllOptions(obj_CountySend); DWRUtil.addOptions(obj_CountySend, { '' : '--请选择--' }); obj_CountySend.disabled = true; AddressAuto.getCountyByCity(pro_Value, function(datas) { // DWRUtil.removeAllOptions(obj_CountySend); // DWRUtil.addOptions(obj_CountySend, { // '' : '--请选择--' // }); obj_CountySend.disabled = false; DWRUtil.addOptions(obj_CountySend, datas); }); if(defaultCounty!=null&&defaultCounty!=''){ setSelectDefault(CountyObj,defaultCounty); } } /* //省变化时 传入区控件的的ID 和 邮编的ID function onCountyChange(CountyObj,PostCodeObj){ var countyObj = document.getElementById(CountyObj); var pro_Index = countyObj.selectedIndex; var county_Value = countyObj.options[pro_Index].value;// 区所选择择的值 var postcodeObj= document.getElementById(PostCodeObj);//邮编对象 AddressAuto.getPostCodeByCounty(county_Value, function(datas) { alert("邮编是:"+datas); postcodeObj.value=datas; }); } */ /** * 设置select 的默认值 * * selectID 控件ID * defaultValue 默认value */ function setSelectDefault(selectID,defaultValue){ var objProvSelect =document.getElementById(selectID); //var sendProv= "${model.shipment.receiveProvince}"; for (var i = 0; i < objProvSelect.options.length; i++) { if (objProvSelect.options[i].value ==defaultValue) { objProvSelect.options[i].selected=true; } } }