你必须使用 阿贾克斯
像这样
function getStates() { $('#state').html(''); var e = document.getElementById("country"); var countryID = e.options[e.selectedIndex].value; $.ajax({ type: "POST", url: "getStates.php", data: {countryID:countryID}, dataType:'json', success: function(result){ var toAppend = ''; $.each(data,function(i,o){ toAppend += '<option>'+o.id+'</option>'; }); $('#state').append(toAppend); }, }); }
getStates PHP
$countryID=$_POST['countryID']; $query = "select id, name from subregions where region_id=".$countryID; $reuslt=RunQuery($query); echo json_encode($reuslt);