jsp页面:
<tr>
<td class="title_2" width="15%" align="center">属地</td>
<td width="15%" colspan="2" align="left">
<select id="cityId" name="cityId" οnchange="init();">
<option value="-1">==请选择==</option>
<s:iterator id="ct" value="cityList">
<option value="<s:property value="#ct.city_id"/>">
<s:property value="#ct.city_name" />
</option>
</s:iterator>
</select>
当前所选属地为:
<select id="subCityId" name="subCityId" >
<option value="-1">===请先选择属地===</option>
</select> (地州)
</td>
</tr>
//初始化区县
function init(){
if($("#cityId").val()!=null && $("#cityId").val()!=-1)
{
$.ajax({
type:"POST",
url:"<s:url value='/liposs/warn/report/highratewarnhousereport/HighRateWarnHouseAction!initDistrict.action'/>",
data:{
"cityId":$("#cityId").val()
},
success:function(data){
$("select[name='subCityId']").html(data);
},
error: function(req, text, err){
alert("获取后台数据异常("+text+"),\n请跟管理员联系.");
}
});
}else{
$("select[name='subCityId']").html("<option value='-1'>===请先选择属地===</option>");
}
}
action:
/**
* 初始化地州列表
*
* @return
*/
public String initDistrict()
{
List<Map> subCityList = new ArrayList<Map>();
subCityList = ResTool.getSubCityList(fo.getCityId(), 1, false);
ajax = appendDistrict(subCityList);
return "ajax";
}
/**
* 初始化地州下拉框
*
* @param list
* @return
*/
@SuppressWarnings("rawtypes")
private String appendDistrict(List<Map> list)
{
StringBuilder sb = new StringBuilder();
if (list == null || list.size() == 0)
{
sb.append("<option value='-1'>==无数据==</option>");
return sb.toString();
}
else
{
sb.append("<option value='-1'>==请选择==</option>");
for (Map map : list)
{
String cityId = String.valueOf(map.get("city_id"));
String cityName = String.valueOf(map.get("city_name"));
if ("00".equals(cityId))
{
sb.append("省中心");
}
else
{
sb.append("<option value='").append(cityId).append("'>")
.append(cityName).append("</option>");
}
}
}
return sb.toString();
}