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

50分求一个DWR实现下拉菜单联动的例子,要完整点的
找了网上的一些例子,看的人晕晕的,好像都是自定义好的,
如果我要从数据库里读了列表以后然后再分的话怎么弄?
求一个完整的例子,或者Email到hmilyld@gmail.com
谢谢了。

------解决方案--------------------
怎么没人理,UP一下
------解决方案--------------------
不知道这个是否符合楼主的要求
类:
package com.ajax;

import java.util.HashMap;
import java.util.Map;

public class SelectValue {
private Map <String,String[]> bike = new HashMap <String,String[]> ();
public SelectValue(){
//从数据库中读取 只需要把读取的数据加入即可,同理。
bike.put( "001 ", new String[]{ "001AA ", "001BB ", "001NNN "});
bike.put( "002 ", new String[]{ "002AA ", "002BB ", "002NNN "});
bike.put( "003 ", new String[]{ "003AA ", "003BB ", "003NNN "});
}
public String[] getYear(){
String[] str = new String[bike.size()];
int i=0;
for(String year:bike.keySet()){
str[i++] = year;
}
return str;
}
public String[] getBike(String key){
return bike.get(key);
}

}

页面:
<%@ page language= "java " import= "java.util.* " pageEncoding= "gbk "%>
<%
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 'selectValue.jsp ' starting page </title>

<script src= 'dwr/interface/SelectValue.js '> </script>
<script src= 'dwr/engine.js '> </script>
<script src= 'dwr/util.js '> </script>

<script type= "text/javascript ">
function refreshYear(){ //刷新列表
SelectValue.getYear(yearList);
}
function yearList(years){
DWRUtil.removeAllOptions( "years ");
DWRUtil.addOptions( "years ",years);//得到列表内容并显示
refreshBike();
}
function refreshBike(){
var year=DWRUtil.getValue( "years ");
SelectValue.getBike(year,bikeList);
}
function bikeList(bikes){
DWRUtil.removeAllOptions( "bikes ");
DWRUtil.addOptions( "bikes ",bikes);
}
function dis(){
var year=DWRUtil.getValue( "years ");
var bike = DWRUtil.getValue( "bikes ");
DWRUtil.setValue( "div ",year);
DWRUtil.setValue( "div1 ",bike);

}
</script>
</head>

<body onload= "refreshYear() ">
<form action= "# "> </form>
请选择年分:
<select id= "years " onchange= "refreshBike() "> </select>
<br>
请选择型号:
<select id= "bikes " size= "4 "> </select>
<br> <br> <br> <br>
<input type= "button " onclick= "dis() " name= "ss " value= "cilck "> </input>
<dir id= "div "> </dir>
<dir id= "div1 "> </dir>