谁帮看一下,是哪里不对?二级联动没有得到预想的效果

业余编程爱好者 发布于 2017/07/12 22:47
阅读 84
收藏 0

1,index.html 
<html> 
<head> 
<meta charset =“utf-8”> 
<title>省州联动</ title> 
<meta name =“renderer”content =“webkit”> 
<meta http-equiv = “X-UA-Compatible”content =“IE = edge,chrome = 1”> 
<meta name =“viewport”content =“width = device-width,initial-scale = 1,maximum-scale = 1”> 
<meta name =“apple-mobile-web-app-status-bar-style”content =“black”> 
<meta name =“apple-mobile-web-app-capable”content =“yes”> 
<meta name =“format -detection“content =”phone = no“> 
<script type =”text / javascript“src =”jquery-3.2.1 / jquery-3.2.1.js“> </ script> 
<script type =”text / javascript “> 
function getSelectVal(){ 
$ .getJSON(”server.php“,{province:$(”#province“)。val()},function(json){ 
var state = $(”#state“); 
$ (“option”,state).remove(); //清空原有的选项
$ .each(json,function(index,array){ 
var option =“<option value ='”+ array ['State_Name'] + “'>”+ array ['State_Name'] +“</ option>”; 
state.append(option); 
}); 
}); 

$(function(){ 
getSelectVal(); 
$(“#province”)select(function(){ 
getSelectVal(); 
}); 
}); 
</ script>
</ head> 
<body> 
<form action =“”method =“get”> 
<select name =“province”id =“province”> 
<option>云南省</ option> 
<option>广西省</选项> 
<选项>四川省</选项> 
</选择> 
<选择name = “状态” ID = “状态”的onChange = “”> 
<选项>项目1 </选项> 
</选择> 
</形式> 
</ body> 
</ html> 

2,server.php 
<!DOCTYPE html PUBLIC“ - // W3C // DTD XHTML 1.0 Transitional // EN”“http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd“> 
<html xmlns =”http://www.w3.org/1999/xhtml“> 
<head> 
<meta http-equiv =”Content-Type“content =”text / html; charset = utf-8“/> 
<title>无标题文档</ title> 
</ head> 
<body> 
<?php 
include'conn.php' 
mysql_select_db('pcsinformation')或者die(“选择数据库失败!”); 
$ province = $ _GET [“province”]; 
if(isset($ province)){ 
$ q = mysql_query(“select * from address_state_table where State_Province = $ province”); 
while($ row = mysql_fetch_array($ q)){ 
$ select [] = array(“id”=> $ row [State_ID],“title”=> $ row [State_Name]); 

echo json_encode($ select); 

?> 
</ body> 
</ html> 

3.数据表内容

数据表

加载中
返回顶部
顶部