js|server|菜单
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>四级连动菜单</title>
</head>
<body>
<form name="frm">
<select name=yijilei onchange="MulSelect(3)"></select>
<select name=erjilei onchange="MulSelect(2)"></select>
<select name=sanjilei onchange="MulSelect(1)"></select>
<select name=sijilei></select>
</form>
<script>
var arrSel=["yijilei","erjilei","sanjilei","sijilei"]
arrData=[];
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from news_lb";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
arrData[arrData.length]=["<%=rs.getString("news_lb_name")%>","<%=rs.getString("news_lb_e")%>","<%=rs.getString("news2")%>","<%=rs.getString("news3")%>"]
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</script>
<script>
function MulSelect(num){
var i,j,arrTemp=[];
for(i=0;i<num;i++)arrTemp[i]=eval("document.frm."+arrSel[i]).value
if(num<arrSel.length)
with(eval("document.frm."+arrSel[num])){
length=0
for(i=0;i<arrData.length;i++){
var find=false
for(j=0;j<num;j++)if(arrTemp[j]!=arrData[i][j])break;
if(j!=num)continue;
for(m=0;m<options.length;m++)if(options[m].text==arrData[i][num])find=true
if(length==0||!find){
options[options.length]=new Option(arrData[i][num],arrData[i][num])
}
}
MulSelect((num+1))
}
}
MulSelect(0)
</script>
</body>
</html>