body部分
<#--四级联动-->
<script src="${request.contextPath}/script/jquery.citys.js"></script>
<div id="demo3" class="citys">
<p>
<select class="selct" id="pro" name="province"></select>
<select class="selct" id="cit" name="city"></select>
<select class="selct" id="are" name="area"></select>
<select class="selct" id="tow" name="town"></select>
</p>
</div>
js部分:
var patha="${request.contextPath}";
var adrrs = "";
var $town = $('#demo3 select[name="town"]');
var townFormat = function(info) {
$town.hide().empty();
if(info['code'] % 1e4 && info['code'] < 7e5) { //是否为“区”且不是港澳台地区
if((info['code'] % 1e3) % 100 > 0) {
$.ajax({
url: '${request.contextPath}/town/' + info['code'] + '.json',
dataType: 'json',
success: function(town) {
$town.show();
for(i in town) {
$town.append('<option value="' + i + '">' + town[i] + '</option>');
}
}
});
}
}
};
$('#demo3').citys({
required: false,
nodata: 'disabled',
onChange: function(data) {
townFormat(data);
}
}, function(api) {
var data = api.getInfo();
townFormat(data);
});