【ajax+php】动态展示4级单位(省、市、县、镇)
生活随笔
收集整理的這篇文章主要介紹了
【ajax+php】动态展示4级单位(省、市、县、镇)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、本篇教程以ajax+php動(dòng)態(tài)展示【省、市、縣、鎮(zhèn)】四級(jí)地區(qū)單位
2、效果圖: ????
3、不廢話,貼代碼!
HTML:
<div class="form-group"><label class="col-sm-3 control-label" for="onecity"> 地區(qū)分類<span class="text-danger">*</span></label><div class="col-sm-2"><select class="form-control" id="onecity" name="onecity" onchange="city()"><option value="">請(qǐng)選擇一級(jí)地區(qū)</option>{loop $one $v}<option value="{$v['id']}">{$v['name']}</option>{/loop}</select></div><!-- 二級(jí)城市 --><div class="col-sm-2" id="ss"></div><!-- 三級(jí)城市 --><div class="col-sm-2" id="ss2"></div><div class="col-sm-2" id="ss3"></div><script text="text/javascript">function city(){var one=$("#onecity").val();$.ajax({type: "POST",url: "/index.php?do=pubh***_third&id=19&step=step1_third&fc=1&one="+one,success: function(msg){$("#ss").empty();$("#ss").append(msg);}}); }</script><script text="text/javascript">function city2(){var two=$("#twocity").val();$.ajax({type: "POST",url: "/index.php?do=pubh***_third&id=19&step=step1_third&fc=2&two="+two,success: function(msg){$("#ss2").empty();$("#ss2").append(msg);}}); }</script><script text="text/javascript">function city3(){var three=$("#threecity").val();$.ajax({type: "POST",dataType: 'json',url: "/index.php?do=pubh***_third&id=19&step=step1_third&fc=3&three="+three,success: function(res){$("#ss3").empty();if(res.data!='error'){$("#ss3").append(res.data);}}}); }</script></div>php:
//1、首先將省級(jí)單位給輸出到頁面 -- 1225$one=db_factory::get_table_data("*",'w***_district','upid=0');//2、ajax動(dòng)態(tài)判斷傳過來的pid(省),獲取市級(jí)單位,并動(dòng)態(tài)輸出<select><option>數(shù)據(jù)htmlif($_R[fc]==1){if($_R['one']){$msg=db_factory::get_table_data("*","w***_district","upid=".$_R['one']);}$dis='<select class="form-control" name="twocity" id="twocity" οnchange="city2();choose_village();"><option value="">請(qǐng)選擇二級(jí)地區(qū)</option>';foreach($msg as $v){$dis.='<option value="'.$v[id].'">'.$v[name].'</option>';}$dis.='</select>';echo $dis;die;}if($_R[fc]==2){if($_R['two']){$msg=db_factory::get_table_data("*","w***_district","upid=".$_R['two']);}$dis='<select class="form-control" name="threecity" id="threecity" οnchange="city3();"><option value="">請(qǐng)選擇三級(jí)地區(qū)</option>';foreach($msg as $v){$dis.='<option value="'.$v[id].'">'.$v[name].'</option>';}$dis.='</select>';echo $dis;die;}if($_R[fc]==3){if($_R['three']){$msg=db_factory::get_table_data("*","wi***_district","upid=".$_R['three']);}/* 四級(jí)單位有可能沒有的,比如直轄市、自治州 */if($msg){$dis='<select class="form-control" name="fourcity" id="fourcity" ><option value="">請(qǐng)選擇四級(jí)地區(qū)</option>';foreach($msg as $v){$dis.='<option value="'.$v[id].'">'.$v[name].'</option>';}$dis.='</select>';kekezu::echojson("",1,$dis);//echo $dis;die;}else{kekezu::echojson("",2,'error');//參數(shù)依次msg、status、datadie ();}}?
到這里就結(jié)束了,很簡(jiǎn)答的一個(gè)ajax應(yīng)用。
?
總結(jié)
以上是生活随笔為你收集整理的【ajax+php】动态展示4级单位(省、市、县、镇)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Guava Cache 1(脉络)
- 下一篇: Node应用的Systemd启动(转)