【发布时间】:2015-03-19 11:44:16
【问题描述】:
我有here 我的项目的代码和流程我有 3 在这里选择一个大陆一个国家一个城市我从 ajax 请求中获取数据来填充这些选择它现在工作正常我只想做一个有点花哨所以我想要一些功能
1.当大陆选择该大陆列表,在国家名单上列出了当发生变化时,我想要城市 还要显示目前国内第一个入境的城市 它没有发生我所做的是我仍然需要更改条目 在国家/地区选择以显示城市列表
2.问题是我是否需要在大陆的 ajax 请求中添加另一个 ajax 请求我不确定这个是否可行我试过了, 暂时不行
Ajax 代码
$('.continentname').change(function() {
var id = $(this).find(':selected')[0].id;
//alert(id);
$.ajax({
type:'POST',
url:'../include/continent.php',
data:{'id':id},
success:function(data){
// the next thing you want to do
var country= document.getElementById('country');
$(country).empty();
var city = document.getElementById('city');
$(city).empty();
for (var i = 0; i < data.length; i++) {
$(country).append('<option id=' + data[i].sysid + ' value=' + data[i].name + '>' + data[i].name + '</option>');
}
}
});
});
$('.countryname').change(function() {
var id = $(this).find(':selected')[0].id;
$.ajax({
type:'POST',
url:'../include/country.php',
data:{'id':id},
success:function(data){
// the next thing you want to do
var city = document.getElementById('city');
$(city).empty();
for (var i = 0; i < data.length; i++) {
$(city).append('<option id=' + data[i].sysid + ' value=' + data[i].name + '>' + data[i].name + '</option>');
}
}
});
});
从数据库中,我将值放入选项中,像这样选择
$("#continent").val(continentid);
$("#continent").change();
$("#country").change();
$("#country").val(countryid);
$("#city").val(cityid);
【问题讨论】:
标签: javascript php jquery ajax select