<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<select id="province" name="province">
<option value="">请选择</option>
</select>
<select id="city" name="city">
<option value="">请选择</option>
</select>
<select id="agency" name="agency">
<option value="">请选择</option>
</select>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="js/三级联动数据.js"></script>
<script type="text/javascript">
for(var a in data[0]) {
var province = $("<option value=‘‘></option>");
$("#province").append(province);
province.text(data[0][a]);
province.val(a);
}
var cityKey;
$("select[name=province]").on("change", function(){
$("#city")[0].options.length = 1;
$("#agency")[0].options.length = 1;
cityKey = "0," + $(this).val();
for(var b in data[cityKey]){
var city = $("<option value=‘‘></option>");
$("#city").append(city);
city.text(data[cityKey][b]);
city.val(b);
}
});
$("select[name=city]").on("change", function(){
var agencyKey = cityKey + "," + $(this).val();
for(var c in data[agencyKey]){
var agency = $("<option value=‘‘></option>");
$("#agency").append(agency);
agency.text(data[agencyKey][c]);
agency.val(c);
}
});
</script>
</html>