你可以这样做。
<!DOCTYPE html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var myJson = {
"country": [
{
"name": "United States",
"id": "usa",
"states": [
{
"name": "State 1 USA",
"id": "usaState1",
"cid": "usa",
"cities": [
{
"name": "City 1",
"id": "usaState1City1",
"area": "12345 sqkm"
},
{
"name": "City 2",
"id": "usaState1City2",
"area": "12345 sqkm"
}
]
},
{
"name": "State 2 USA",
"id": "usaState2",
"cid": "usa",
"cities": [
{
"name": "City 3",
"id": "usaState2City3",
"area": "12345 sqkm"
},
{
"name": "City 4",
"id": "usaState2City4",
"area": "12345 sqkm"
}
]
}
]
},
{
"name": "Australia",
"id": "aus",
"states": [
{
"name": "State 1 Australia",
"id": "ausState1",
"cid": "aus",
"cities": [
{
"name": "City 5",
"id": "ausState1City5",
"area": "12345 sqkm"
},
{
"name": "City 6",
"id": "ausState1City6",
"area": "12345 sqkm"
}
]
},
{
"name": "State 2 Australia",
"id": "ausState2",
"cid": "aus",
"cities": [
{
"name": "City 7",
"id": "ausState2City7",
"area": "12345 sqkm"
},
{
"name": "City 8",
"id": "ausState2City8",
"area": "12345 sqkm"
}
]
}
]
}
]
}
$(document).ready(function(){
$.each(myJson.country, function (index, value) {
$("#country").append('<option value="'+value.id+'">'+value.name+'</option>');
});
$("#country").click(function () {
var countryId = $(this).val();
if(cntryId !=''){
$('#selectedvalue').val($(this).val());
}else{
$('#selectedvalue').val($(this).val());
}
var cntryId =$('#selectedvalue').val();
var exist = cntryId.indexOf(',');
if(parseInt(exist) > 0){
$("#state").html('');
var array = cntryId.split(",");
$.each(array,function(i){
selectedId =array[i];
getState(selectedId);
});
}else{
$("#state").html('');
getState(cntryId)
}
});
});
function getState(countryId){
$.each(myJson.country, function (index, value) {
var state =value.states;
$.each(state, function (indexState, valueState) {
if(countryId==valueState.cid){
$("#state").append('<option value="'+value.indexState+'">'+valueState.name+'</option>');
}
});
});
}
</script>
<form id="dropdowns" action="index.html">
<label>Country:</label>
<select id="country" name="country" multiple>
<option value="000">-Select Country-</option>
</select>
<br />
<label>State:</label>
<select id="state" name="network">
<option value="000">-Select State-</option>
</select>
<br />
<label>City:</label>
<select id="model" name="model">
<option value="000">-Select City-</option>
</select>
<br />
<input type="hidden" id="selectedvalue" value="">
</form>
</body>
</html>
document
。 - Jaistate
对于键“美国”包含不同的值。 - icke