<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax省市区三级联动</title>
</head>
<body>
省: <select name="" id="pro"></select>
市: <select name="" id="city"></select>
区: <select name="" id="area"></select>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
$(function(){
$.getJSON('./1.json',function(data){
let option = '<option value="">选择</option>';
$.each(data,function(i){
option += '<option value="'+data[i].proId+'">'+data[0].proName+'</option>';
})
$('#pro').html(option);
})
});
$('#pro').change(function(){
$.getJSON('./2.json',function(data){
let option = '<option value="">选择</option>';
$.each(data,function(i){
if(data[i].proId==$('#pro').val()){
option += '<option value="'+data[i].cityId+'">'+data[0].cityName+'</option>';
}
})
$('#city').html(option);
});
}) $('#city').change(function(){
$.getJSON('./3.json',function(data){
let option = '<option value="">选择</option>';
$.each(data,function(i){
if(data[i].cityId==$('#pro').val()){
option += '<option value="'+data[i].areaId+'">'+data[0].areaName+'</option>';
}
})
$('#area').html(option);
})
});
</script>
</body>
</html>