模板部分代码:
<form method='post' action='' id='myform' name='myform'>
<dl><dt>地址</dt>
<dd>
<select name='prov' id='prov'>
<option value=''>省份</option>
<?php $prov=M('')->where($where)->order('order')->select();?>
<?php foreach($prov as $k){?>
<option value='<?php echo $k["id"];?>'><?php echo $k['name'];?></option>
<?php }?>
</select>
<select name='city' id='city'>
<option value=''>城市</option>
</select>
<select name='zone' id='zone'>
<option value=''>区域</option>
</select>
</dd>
</dl>
</form>
<script>
$('#prov').on('change',function(){
if($(this).val()=='')
$('#city').empty();
else {
var prov=$(this).val();
$.get('/index.php/moduel/controller/getcity?prov='+prov,function(data){
var s='';
$.each(data,function(i,n){
s+='<option value="'+n.id+'">'+n.name+'</option>';
});
$('#city').html(s);
$('#city').trigger('change');
});
}
});
$('#city').on('change',function(){
if($(this).val()=='')
$('#zone').empty();
else {
var city=$(this).val();
$.get('/index.php/moduel/controller/getzone?city='+city,function(data){
var s='';
$.each(data,function(i,n){
s+='<option value="'+n.id+'">'+n.name+'</option>';
});
$('#zone').html(s);
});
}
});
</script>
控制器部分代码:
<?php
namespace appmoduelcontroller;
class Controller extends controller
{
public function getcity()
{
$prov=$_GET['prov'];
$where=;
if($prov==2||$prov==3||$prov==4||$prov==5)
$where=array('linkageid'=>$prov,'keyid'=>1,'city'=>1);
$data=;
return $data;
}
public function getzone()
{
$city=$_GET['city'];
$where=;
$data=;
return $data;
}
}
?>