关于动态三级联动的问题
我做的个页面包含三级联动,我看了大多数的实现都是建好几个表实现的,我想可不可以在一个表里实现三级联动 ,比如把三种类型全放在1个表里
下面是个例子,哪位高手帮忙改一改或有更好的方法.
总共三级,通过学院department选择系division,通过系选择专业speciality
<%@ page language= "java " import= "java.util.*,java.lang.*,java.sql.* " pageEncoding= "GB18030 "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<script language= "javascript ">
var DeparmentCount; //三级联动菜单代码
DeparmentCount = 0;
var DivisionCount;
DivisionCount = 0;
var SpecialityCount;
SpecialityCount = 0
Department = new Array();
Division = new Array();
Speciality = new Array();
<%
system.pub.oraclesql myDao = new system.pub.oraclesql();
ResultSet rs = myDao.execQuery( "select * from division ");
int i=0;
for(rs.next();!rs.isAfterLast();rs.next(),i++){%>
Division[ <%=i%> ] = new Array( " <%=rs.getString( "Division_name ")%> ", " <%=rs.getString( "department_id ")%> ", " <%=rs.getString( "id ")%> ");
<% }%>
DivisionCount = <%=i%> ;
<%
System.out.println( "debug....1 ");
rs = myDao.execQuery( "select * from speciality ");
i=0;
for(rs.next();!rs.isAfterLast();rs.next(),i++){%>
Speciality[ <%=i%> ] = new Array( " <%=rs.getString( "Speciality_name ")%> ", " <%=rs.getString( "division_id ")%> ", " <%=rs.getString( "id ")%> ");
<% }%>
SpecialityCount = <%=i%> ;
function changeDepartment(DepartmentId){
document.form1.Switch.value= "false ";
document.form1.division.length = 0;
var DepartmentId = DepartmentId;
var i;
for (i=0;i < DivisionCount; i++){
if (Division[i][1] == DepartmentId){
document.form1.division.options[document.form1.division.length] = new Option(Division[i][0], Division[i][2]);
}
}
changeDivision(document.form1.division.value);
}
function changeDivision(DivisionId){
document.form1.Switch.value= "false ";
document.form1.speciality.length = 0;
var DivisionId = DivisionId;
var i;
for (i=0;i < SpecialityCount; i++){
if (Speciality[i][1] == DivisionId){
document.form1.speciality.options[document.form1.speciality.length] = new Option(Speciality[i][0], Speciality[i][2]);
}
}
if(document.form1.speciality.length!=0){
document.form1.speciality.style.visibility = 'visible ';
}
else{
document.form1.speciality.style.visibility = 'hidden ';
}
}
function initialSelect(){
changeDepartment(document.form1.department.options[document.form1.department.selectedIndex].value);
}
</script>
</head>
<body onload= "initialSelect(); ">
<form name= "form1 ">
<select name= "department " size= "1 " id= "department " style= "width:20% " onChange= "changeDepartment(document.form1.department.options[document.form1.department.selectedIndex].value) ">
<%
rs = myDao.execQuery( "select * from department ");
i=0;
for(rs.next();!rs.isAfterLast();rs.next(),i++){%>
<option value= " <%=rs.getString( "id ")%> "> <%=rs.getString( "Department_name ")%> </option>
<% }%>
</select>
<select name= "division " size= "1 " id= "division " onChange= "changeDivision(document.form1.division.options[document.form1.division.selectedIndex].value) ">
</select>
<input type= "hidden " name= "Switch " value= "false ">
<select name= "speciality " size= "1 ">
</select>
</form>
</body>
</html>
[解决办法]
无限级联动,如果是小型数据的话,比如定义一个公司,.公司下面有部门.部门下面有职位,职位下面有职员和员工,
建议用xml来做数据库,
参考技术用dom4j
去摆渡一下,好多案列
[解决办法]
用DWR实现吧,很简单的,网上有例子。
[解决办法]
这个用ajax做比较清晰,不过你得现学.
[解决办法]
Ajax实现三级联动下拉框
http://www.blogjava.net/rickhunter/articles/62571.html
[解决办法]
其实大部分都是用一个表实现的
[解决办法]
我个人认为用ajax很容易,
dwr包很容学,楼主写的代码太乱了,估计过几天自己也看不懂
[解决办法]
曾经用Ajax实现二级联动,觉得很方便,可以试一下