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

三级联动下拉框,数据从数据库中存,怎么实现?
有人说用ajax,
或js都行.
请讲讲思路,和实例.

------解决方案--------------------
<html>
<head>
<script language=javascript>
var arr= "浙江|江苏|安徽|江西 ";

var arr0 = "杭州|宁波|温州|绍兴 "; //这些数据可以从数据库中取得
var arr1 = "南京|苏州|无锡|常州 ";
var arr2 = "合肥|翕县|黄山|祁门 ";
var arr3 = "南昌|九江|赣州|上饶 ";

var arr00 = "杭州A区|杭州B区 ";
var arr01 = "宁波A区|宁波B区 ";
var arr02 = "温州A区|温州B区 ";
var arr03 = "绍兴A区|绍兴B区 ";

var arr10 = "南京A区|南京B区 ";
var arr11 = "苏州A区|苏州B区 ";
var arr12 = "无锡A区|无锡B区 ";
var arr13 = "常州A区|常州B区 ";

var arr20 = "合肥A区|合肥B区 ";
var arr21 = "翕县A区|翕县B区 ";
var arr22 = "黄山A区|黄山B区 ";
var arr23 = "祁门A区|祁门B区 ";

var arr30 = "南昌A区|南昌B区 ";
var arr31 = "九江A区|九江B区 ";
var arr32 = "赣州A区|赣州B区 ";
var arr33 = "上饶A区|上饶B区 ";

//alert(eval( "arr "+2+1));
function AddOptions(dltObj,arrObj)
{
dltObj.innerHTML= " ";
var arrLocation=arrObj.split( "| ");
for(var i=0;i <arrLocation.length;i++){
var opt=document.createElement( "OPTION ");
dltObj.add(opt);
opt.value=i;
opt.text=arrLocation[i];
}
}
function init(){
AddOptions(dltProvince,eval( 'arr '));
AddOptions(dltCity,eval( 'arr '+dltProvince.selectedIndex));
AddOptions(dltArea,eval( 'arr '+dltProvince.selectedIndex+dltCity.selectedIndex));
}
</script>
</head>
<body onLoad= "init(); ">
<table width= "300 " cellpading= "0 " cellspacing= "0 " border= "0 ">
<tr>
<td width= "100 "> <select id= "dltProvince " onchange= "AddOptions(dltCity,eval( 'arr '+dltProvince.selectedIndex));AddOptions(dltArea,eval( 'arr '+dltProvince.selectedIndex+dltCity.selectedIndex)); " style= "width:100% "> </select>
</td>
<td width= "100 "> <select id= "dltCity " onchange= "AddOptions(dltArea,eval( 'arr '+dltProvince.selectedIndex+dltCity.selectedIndex)); " style= "width:100% "> </select>
</td>
<td width= "100 "> <select id= "dltArea " style= "width:100% "> </select>
</td>
</tr>
</table>
</body>
</html>

------解决方案--------------------
//=================公司类方法===================//
public String getDrop(String compid,String dataid) throws Exception{
if(str.IsEmpty(dataid) )
dataid= "AAA ";
Compid com[]=this.readAll(compid,dataid);
StringBuffer bf = new StringBuffer();
if(com.length > 0){
for(int i=0;i <com.length ;i++){
if(dataid.equals(com[i].getBh()