日期:2014-05-18  浏览次数:20921 次

求级联下拉框代码
jsp+ajax+mysql   的下拉选择框效果(最好是二级的),选择框中的内容为从数据库读取的内容!


------解决方案--------------------
可以告诉你思路:
首先从数据库读出第一个select数据别表出所有信息
<select name= "ceshixitongmingcheng " onchange= "ceshi(this.form) ">
<option value=-1> -=请选测试名称-= </option>
<%
ArrayList list =km_fwCsDAO.selectCeshiXitong();
for(int i=0;i <list.size();i++){
String ceshixitongmingcheng = (String)list.get(i);
out.print( " <option value= ");
out.print(ceshixitongmingcheng);
if(request.getParameter( "ceshixitongmingcheng ")!=null&&new String(request.getParameter( "ceshixitongmingcheng ").getBytes( "iso8859-1 "), "gb2312 ").equals(ceshixitongmingcheng)){
out.print( " selected ");
}
out.print( "> ");
out.print(ceshixitongmingcheng);
out.print( " </option> ");
}
%>
</select>

当数据改变调用js方法ceshi(this.form)
function ceshi(selects){
var ceshixitongmingcheng=selects.ceshixitongmingcheng.value
var ceshishujushuxing= ' ';
if(ceshixitongmingcheng != '-1 ' ){
location= '/work/km_fwcs.jsp?ceshixitongmingcheng= '+ceshixitongmingcheng;//返回本页,带上参数
}
}

下面页面接收参数String canshu=request.getParameter( "ceshixitongmingcheng ");进行处理
如果canshu不等于空则进行下个select查询并输出结果
<select name= "ceshishujushuxing " >
<option value=-1> -=请选测试属性-= </option>
<%
if(request.getParameter( "ceshixitongmingcheng ")!=null){
ArrayList lista =km_fwCsDAO.selectCeshiShuxing(Change.tran(request.getParameter( "ceshixitongmingcheng ")));
for(int i=0;i <lista.size();i++){
String ceshishujushuxing = (String)lista.get(i);
out.print( " <option value= ");
out.print(ceshishujushuxing);
if(request.getParameter( "ceshishujushuxing ")!=null&&request.getParameter( "ceshishujushuxing ").equals(ceshishujushuxing)){
out.print( " selected ");
}
out.print( "> ");
out.print(ceshishujushuxing);
out.print( " </option> ");
}
}
%>
</select>

大概流程就这样,这种方法比较容易接受!

------解决方案--------------------
给你几段我以前写的代码 :
public Vector TreeListLoading(String levelId,String parentId,
String name,
int position,
String level,
StringBuffer outHTML,
boolean init) {
//表示用户不属于任何一个组
if (levelId == " ") {
return new Vector();
} else {
//存放所有页面组件级别的form属性名
Vector buttonLevelList = new Vector();
//定义Vector对象childList存放所有孩子的ID
Vector childList = new Vector();
//定义Vector对象nameList存放所有孩子的名称
Vector nameList = new Vector();
//定义Vector对象pageList存放所有二级节点对应的页面的ID
Vector pageList = new Vector();
//定义查询语句用来获得参数parentId对应的孩子信息
String sqlGetChild = "SELECT ClassId,Name,pageId " +