Liferay + JQuery实现三级联动

function changeSelect(t){
			var id = t.value;
			if(id == -1){
				clearCity();
				clearCounty();
			}else{
				Liferay.Service.dms.Regions.findRegionsByRegionId({regionId: id},function(regions){
					var len = regions.length
					var optCity="<option value='-1' selected='selected'>请选择市</option>";
					for(var i=0; i<len;i++){
						optCity = optCity+"<option value='"+regions[i].regionId+"'>"+regions[i].regionName+"</option>"
					}
					$("select[name='cityID']").html(optCity);
					$("select[name='cityID']").attr("value",'-1');
					clearCounty();
				});
			}

	}
	
	function changeSelectCity(t){
			var id = t.value;
			if(id == -1){
				clearCounty();
			}else{
				Liferay.Service.dms.Regions.findRegionsByRegionId({regionId: id},function(regions){
					var len = regions.length
					var opt="<option value='-1' selected='selected'>请选择区县</option>";
					for(var i=0; i<len;i++){
						opt = opt+"<option value='"+regions[i].regionId+"'>"+regions[i].regionName+"</option>"
					}
					$("select[name='countyID']").html(opt);
					$("select[name='countyID']").attr("value",'-1');
				});
			}

	}
	//--清除市选项 --
	function clearCity(){
		var optCounty="<option value='-1' selected='selected'>请选择市</option>";
		$("select[name='cityID']").html(optCounty);
		$("select[name='cityID']").attr("value",'-1');
	}
	//--清除区县选项 --
	function clearCounty(){
		var optCounty="<option value='-1' selected='selected'>请选择区县</option>";
		$("select[name='countyID']").html(optCounty);
		$("select[name='countyID']").attr("value",'-1');
	}

 

你可能感兴趣的:(html,jquery)