日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

ThinkPHP+AJAX三级联动

發布時間:2024/10/12 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ThinkPHP+AJAX三级联动 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

sanji.html

<!doctype html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><load href ="__PUBLIC__/JQ/jquery-1.12.4.min.js"/> </head> <body><h1>三級聯動</h1> <div id='sanji'> <select id = 'sheng'></select><select id ='shi'></select><select id = 'xian'></select> </div> </body> </html> <script>$(document).ready(function(e){sheng(); shi(); xian();//省級列表數據function sheng(){$.ajax({url:"__CONTROLLER__/sheng",dataType:"json", async:false, //同步 success:function(sheng){var str ='';for(var i=0;i<sheng.length;i++){str += "<option value = " + sheng[i].pro_id +">"+ sheng[i].pro_name + "</option>";}$("#sheng").html(str); //填充省級列表 }});}//市級列表數據function shi(){var id = $("#sheng").val();$.ajax({url:"__CONTROLLER__/shi",data:{id:id},dataType:"json",async:false, //同步 type:"post",success:function(shi){var str = '';for(var i=0;i<shi.length;i++){str += "<option value=" + shi[i].city_id +">"+ shi[i].city_name + "</option>";}$("#shi").html(str); //填充市級列表 }});}function xian(){var id = $("#shi").val();$.ajax({url:"__CONTROLLER__/xian",data:{id:id},dataType:"json",async:false, //同步 type:"post",success:function(xian){var str = '';for(var i=0;i<xian.length;i++){str += "<option value=" + xian[i].cou_id +">"+ xian[i].cou_name + "</option>";}$("#xian").html(str); //填充縣級列表 }});}$("#sheng").change(function(){shi();xian();});$("#shi").change(function(){xian();});});</script> View Code

SanjiController.class.php

<?php namespace Home\Controller; use Think\Controller; class SanjiController extends Controller{public function sanji(){$this->display();} //省級列表public function sheng(){$pro = M('pro');$sheng = $pro->select();$this->ajaxReturn($sheng);}//市級列表public function shi(){$id = I('id');$city = M('city');$shi = $city->where(array('pro_id'=>$id))->select();$this->ajaxReturn($shi);}public function xian(){$id = I('id');$cou = M('cou');$xian = $cou->where(array('city_id'=>$id))->select();$this->ajaxReturn($xian);}}?> View Code

省級表?        市級表  

?

?

縣級表   

?

注:表中數據僅作為練習所用,請不要對號入座!

轉載于:https://www.cnblogs.com/sihuiming/p/5540983.html

總結

以上是生活随笔為你收集整理的ThinkPHP+AJAX三级联动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。