<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<jsp:useBean id="DBConn" scope="page" class="com.JDBConnection"/>
<%
//连接Access 数据库
String dbpath="data/lyb.mdb"; //数据库的路径,请自行修改
Connection conn=DBConn.getConnToAccess(application.getRealPath(dbpath));
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select * from mu where itemid <>0 order by id asc";
ResultSet rs=stmt.executeQuery(sql);
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
var count = 0;
while(rs.next()){
%>
subcat[<%=count%>] = new Array("<%=rs.getString(1)%>","<%=rs.getInt(2)%>","<%=rs.getInt(0)%>");
<%
}
DBConn.close();
%>
onecount=<%=count%>;function changelocation(locationid)
{
document.form1.Nclassid.length = 0; var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form1.Nclassid.options[document.form1.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
</head><form id="form1" name="form1" method="post" action="news.asp?wang=add">
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td> <%
Statement stmt1=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql = "select * from mu where itemid = 0 order by id asc";
ResultSet rs1=stmt1.executeQuery(sql);
%>
<select name="classid" onChange="changelocation(document.form1.classid.options[document.form1.classid.selectedIndex].value)" size="1">
<option value="">选择栏目</option>
<%while(rs.next()){%>
<option value="<%=rs1.getInt(0)%>"><%=rs1.getString(1)%></option>
<%
}
%>
</select>
<select name="Nclassid">
<option value="">选择栏目</option>
</select> </td>
</tr>
</table></form>
mu表有三个字段:id,name,itemid(子索引),classid(父索引),高手看看这段代码有什么问题?谢谢!!
import="java.sql.*" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<jsp:useBean id="DBConn" scope="page" class="com.JDBConnection"/>
<%
//连接Access 数据库
String dbpath="data/lyb.mdb"; //数据库的路径,请自行修改
Connection conn=DBConn.getConnToAccess(application.getRealPath(dbpath));
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select * from mu where itemid <>0 order by id asc";
ResultSet rs=stmt.executeQuery(sql);
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
var count = 0;
while(rs.next()){
%>
subcat[<%=count%>] = new Array("<%=rs.getString(1)%>","<%=rs.getInt(2)%>","<%=rs.getInt(0)%>");
<%
}
DBConn.close();
%>
onecount=<%=count%>;function changelocation(locationid)
{
document.form1.Nclassid.length = 0; var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form1.Nclassid.options[document.form1.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
</head><form id="form1" name="form1" method="post" action="news.asp?wang=add">
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td> <%
Statement stmt1=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql = "select * from mu where itemid = 0 order by id asc";
ResultSet rs1=stmt1.executeQuery(sql);
%>
<select name="classid" onChange="changelocation(document.form1.classid.options[document.form1.classid.selectedIndex].value)" size="1">
<option value="">选择栏目</option>
<%while(rs.next()){%>
<option value="<%=rs1.getInt(0)%>"><%=rs1.getString(1)%></option>
<%
}
%>
</select>
<select name="Nclassid">
<option value="">选择栏目</option>
</select> </td>
</tr>
</table></form>
mu表有三个字段:id,name,itemid(子索引),classid(父索引),高手看看这段代码有什么问题?谢谢!!
pageEncoding="gb2312"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <SCRIPT LANGUAGE="JavaScript">
<!--
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
} function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
} var dsy = new Dsy(); dsy.add("0",["1","2","3","4"]); dsy.add("0_0",["11","12","13"]);
dsy.add("0_1",["21","22","23"]);
dsy.add("0_2",["31","32","33"]);
dsy.add("0_3",["41","42","43"]);
//-->
</SCRIPT>
<SCRIPT LANGUAGE = JavaScript>
var s=["s1","s2"];
var opt0 = ["请选择","请选择"];
function setup()
{
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
//-->
</SCRIPT>
</head>
<body bgcolor="#E0E0E0" onload="setup()"> <select id="s1" name="s1"><option></option></select>
<select id="s2" name="s2"><option></option></select> </body>
</html>
感觉这个代码不错,能实现二级无刷新连动,如果我要把它修改成数据库连接,怎么实现?
比如建立两个表:父目录表class(classid,classname)子目录表item(itemid,itemname,classid),拜托各位了!!
手头没代码,你自己搜下,代码很程式化的。