我有像国家/州和城市一样的下拉链。有没有办法等到下降人口继续进行?比如首先加载国家然后根据国家的选择然后加载州和城市....
function populateLists(listType) {
// on success do this:
$.ajax({
type:"POST",
url:"Wizard_Using_PageMethod.aspx/GetCountry",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType:"json"}
});
[WebMethod]
public static CountryList GetCountry()
{
CountryList country = new CountryList();
///go to db and get the data
return country;
}
答案 0 :(得分:3)
你可以这样做
$('#cb_country').change(function(){
var id=$(this).val();
$.get('getCity.php',{id:id},function(data){
$("#cb_city").html(data);
});
});
getCity.php:
<?php
require('../conn.php');
$id=$_GET['id'];
$Q=mysql_query("SELECT * FROM city WHERE CountryID='".$id."' ORDER BY Cityname ASC");
do{
echo "<option value='".$row['CityID']."'>".$row['CityName']."</option>";
}
while($row=mysql_fetch_assoc($Q));