Thinkphp realizes three-level linkage between provinces and municipalities
May 18, 2018 pm 04:21 PMSkip to [1] [2] [3] [4] [Full screen preview]
public function index(){ $province = M('Tree')->where ( array('pid'=>1) )->select (); $this->assign('province',$province); $this->display(); } public function getRegion(){ $Region=M("Tree"); $map['pid']=$_REQUEST["pid"]; $map['type']=$_REQUEST["type"]; $list=$Region->where($map)->select(); echo json_encode($list); }
2. [Code][HTML] Code Skip to [1] [2] [3] [4] [Full screen preview]
<select name="province" id="province" onchange="loadRegion('province',2,'city','{:U('Index/getRegion')}');"> <option value="0" selected>省份/直轄市</option><volist name="province" id="vo"> <option value="{$vo.id}" >{$vo.name}</option></volist> </select> <select name="city" id="city" onchange="loadRegion('city',3,'town','{:U('Index/getRegion')}');"> <option value="0">市/縣</option> </select> <select name="town" id="town"> <option value="0">鎮(zhèn)/區(qū)</option> </select>
3. [Code][JavaScript]Code Jump to [1] [2] [3] [4] [Full screen preview]
function loadRegion(sel,type_id,selName,url){ jQuery("#"+selName+" option").each(function(){ jQuery(this).remove(); }); jQuery("<option value=0>請(qǐng)選擇</option>").appendTo(jQuery("#"+selName)); if(jQuery("#"+sel).val()==0){ return; } jQuery.getJSON(url,{pid:jQuery("#"+sel).val(),type:type_id}, function(data){ if(data){ jQuery.each(data,function(idx,item){ jQuery("<option value="+item.id+">"+item.name+"</option>").appendTo(jQuery("#"+selName)); }); }else{ jQuery("<option value='0'>請(qǐng)選擇</option>").appendTo(jQuery("#"+selName)); } } ); } </script>
4. [Code][SQL]Code Jump to [1] [2] [ 3] [4] [Full screen preview]
DROP TABLE IF EXISTS `tp_tree`; CREATE TABLE `tp_tree` ( `id` int(5) unsigned NOT NULL AUTO_INCREMENT, `pid` int(5) unsigned NOT NULL DEFAULT '0', `name` varchar(120) DEFAULT NULL, `type` tinyint(1) DEFAULT '2', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3410 DEFAULT CHARSET=utf8;
5. [File] TP_tree.sql ~ 215KB Download (7) [Full screen preview]
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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5060533 fails to install in Windows 10?
3 weeks ago
By DDD
Dune: Awakening - Where To Get Insulated Fabric
3 weeks ago
By Jack chen
Gmail Login: How to Sign Up, Sign In, or Sign Out of Gmail - MiniTool
1 months ago
By Jack chen
How to fix KB5060999 fails to install in Windows 11?
3 weeks ago
By DDD
Guild Guide In Tainted Grail: The Fall Of Avalon
4 weeks ago
By Jack chen

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
