Home >php教程 >php手册 >ThinkPHP three-level linkage

ThinkPHP three-level linkage

PHP中文网
PHP中文网Original
2016-08-26 10:12:51832browse

HTML:

<div id="cBox">
<select id="pro">
<option>--请选择省份--</option>
</select>
</div>

JS:

$(function(){
$.ajax({type:&#39;GET&#39;, url:&#39;__URL__/linkage&#39;, data:&#39;upid=0&#39;,
success:function( data ){
var proOption = &#39;&#39;;//用来存放省份的选项
for( var i=0;i<data.length;i++){
proOption += &#39;<option value=&#39;+data[i].id+&#39;>&#39;+data[i].name+&#39;</option>&#39;;
}
$(&#39;#pro&#39;).append(proOption);
}, dataType:&#39;json&#39;
});
$(&#39;#cBox&#39;).on(&#39;change&#39;,&#39;select&#39;,function(){
var ob = $(this);
ob.nextAll(&#39;select&#39;).remove();
var val = $(this).val();
$.get(&#39;__URL__/linkage&#39;, {upid:val}, function(res){
if( res.length <=0 ) return false;
var len = $(&#39;#cBox select&#39;).length;

switch( len ){
case 1:
idValue = &#39;city&#39;;
break;
case 2:
idValue = &#39;qu&#39;;
break;
case 3:
idValue = &#39;xian&#39;;
break;
case 4:
idValue =&#39;dao&#39;;
break;
default:
idValue = &#39;222&#39;;
break;
}
var select = &#39;<select id="&#39;+idValue+&#39;"><option>--请选择--</option>&#39;;
for( var i=0;i<res.length;i++){
select += &#39;<option value="&#39;+res[i].id+&#39;">&#39;+res[i].name+&#39;</option>&#39;;
}
select +=&#39;</select>&#39;;
ob.after( select );
},&#39;json&#39;
);
});
});

 

TP:

public function linkage() {
$map[&#39;pid&#39;] = I(&#39;get.upid&#39;);
$cityList = M(&#39;category&#39;)->where($map)->select();
echo json_encode($cityList);
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn