Home > php教程 > PHP源码 > php ajax 实现三级省市区联动

php ajax 实现三级省市区联动

PHP中文网
Release: 2016-05-25 17:09:25
Original
1257 people have browsed it

                         

           

2. [代码][PHP]代码     跳至                               

public function getdiqudaima(){
		
			$rs = $this->db->table('diqudaima')
					   ->field("province,city,zonename,zonecode")
					   ->where("areaid=1 ")
					   ->getAll();
			$this->db->lastSql();
			return $rs;
		}
		public function getq($code,$n){
		$where = "and zonecode like '$code%'";
			$rs = $this->db->table('diqudaima')
					   ->field("province,city,zonename,zonecode")
					   ->where("areaid = $n ".$where)
					   ->getAll();
			return $rs;
		}
Copy after login

3. [代码][PHP]代码 跳至

public function showdiqu(){
			$test = load_model('Test');
			$data = $test->getdiqudaima();
			$this->output->set('data',$data);
			$this->output->display('test.html');
			
		}
		public function showcity(){
			$test = load_model('Test');
			$code = $this->input->getTrim('code');
			$datacity = $test->getq($code,2);
			echo json_encode($datacity);
		}
		public function showqu(){
			$test = load_model('Test');
			$code = $this->input->getTrim('code');
			$datacity = $test->getq($code,3);
			echo json_encode($datacity);
		}
Copy after login

4. [代码][PHP]代码 跳至

请选择市"); 		
				for(var p in obj){
					$("#city").append(""+obj[p].zonename+"");
				    
				}
			}
		);	
	}
	function getq(){
		var a = $("#pro").val();
		$.post("?c=Test&a=showqu",{code: a},
			function(data){
				var obj = eval('('+data+')');
				$("#zone").empty();
				$("#zone").prepend("请选择区"); 		
				for(var p in obj){
					$("#zone").append(""+obj[p].zonename+"");
				    
				}
			}
		);
	}
" _ue_custom_node_="true">
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template