Home > php教程 > php手册 > body text

ThinkPHP three-level linkage

PHP中文网
Release: 2016-08-26 10:12:51
Original
801 people have browsed it

HTML:

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

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;
);
});
});
Copy after login

 

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);
}
Copy after login


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template