日期:2014-05-17  浏览次数:20712 次

select中的问题
两个select,两个数据库表。一个select从表中取值放到option,然后双击option,根据option的值去取另一个表的对应的一个表的值显示在下一option中


------解决方案--------------------
双击option?建议不要这样。。option的单击双击事件。。如果选择不改变。。很可能触发不了。。

用onchange事件把。。当选择option改变的时候,就触发。。触发的时候,用ajax方式去后台执行查询,然后显示。。。
------解决方案--------------------
赞成楼上所述。。。
------解决方案--------------------
一楼回答很正确
------解决方案--------------------
上论坛搜一下吧,很多。


------解决方案--------------------
ajax省市联动啊
代码:根据你的需求自己改改:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'province.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function loadXMLDoc()

xmlhttp = null;
var country = document.getElementById("country");
country.length = 1;
country.selectedIndex = 0;
var province = document.getElementById("province");
if(province.value == ""){
return ;
}
var url="http://localhost:8080/Ajax_Province/GetProvince?&province="+encodeURIComponent(province.value);
if (window.XMLHttpRequest) {// code for Firefox, Mozilla, IE7, etc.
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp != null) {
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open("post", url, true);
xmlhttp.send(null);
} else {
alert("Your browser does not support XMLHTTP.");
}
}

function state_Change() {
var province = document.getElementById("province");
var country = document.getElementById("country");
if (xmlhttp.readyState == 4&&xmlhttp.status == 200) {// 4 = "loaded"
var serviceData = xmlhttp.responseText;
if(serviceData == null||serviceData == ""){
return;
}
var s = serviceData.split(",");
for(var i=0;i<s.length-1;i++){
country.options[i+1] = new Option(s[i],s[i]);
}
}
}




</script>
</head>
 
<body>
出生地:<select id="province" onchange="loadXMLDoc()">
<option value="">------请选择省-----</option>
<option value="江西省">江西省</option>
<option value="江苏省">江苏省</option>
<option value="浙江省">浙江省</option>
<option value="山东省">山东省</option>
<option value="辽宁省">辽宁省</option>
<option value="福建省">福建省</option>