日期:2014-05-17  浏览次数:20727 次

急求一个三级联动下拉选择框,在线等。
我现在有一个表A,里面的字段和值如下:
ID         parentID             name
10             1                   text1
11             10                 text2
13             10                 text3
14             1                   text4
15             14                 text5
16             14                 text6
17             16                 text7
18             16                 text8
我要查询这个表,得到一个三级联动下拉选择框。
第一级是查询parentID=1得到的
第二级是选择第一级后,再查询parentID=(第一级ID)
第三级是选择第二级后的查找值。

请问这种方式,怎样用代码来实现。在线等,谢谢!!

------解决方案--------------------
<script language = "JavaScript ">
var onecount;
onecount=0;
sub2 = new Array();
sub2[0] = new Array( '1 ', '1 ', 'a1 ');
sub2[1] = new Array( '2 ', '1 ', 'a2 ');
sub2[2] = new Array( '3 ', '1 ', 'a3 ');
sub2[3] = new Array( '4 ', '2 ', 'b1 ');
sub2[4] = new Array( '5 ', '2 ', 'b2 ');
sub2[5] = new Array( '6 ', '3 ', 'c1 ');
sub2[6] = new Array( '7 ', '3 ', 'c2 ');

onecount=7;

sub3 = new Array();
sub3[0] = new Array( '1 ', '1 ', '#1 ');
sub3[1] = new Array( '2 ', '2 ', '#2 ');
sub3[2] = new Array( '3 ', '3 ', '#3 ');
sub3[3] = new Array( '1 ', '4 ', '#4 ');
sub3[4] = new Array( '2 ', '5 ', '#5 ');
sub3[5] = new Array( '1 ', '6 ', '#6 ');
sub3[6] = new Array( '2 ', '7 ', '#7 ');

twocount=7;

function changeone(locationid)
{
document.all.s2.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++){
if (locationid== "* "){
document.all.s2.options[document.all.s2.length] = new Option(sub2[i][2], sub2[i][0]);
}
else{
if (sub2[i][1] == locationid){
document.all.s2.options[document.all.s2.length] = new Option(sub2[i][2], sub2[i][0]);
}
}
}
changetwo(document.all.s2.options[0].value)
}
function changetwo(locationid)
{
document.all.s3.length = 0;
var locationid=locationid;
var i;
for (i=0;i < twocount; i++){
if (locationid== "* "){
document.all.s3.options[document.all.s3.length] = new Option(sub3[i][2], sub3[i][0]);
}
else{
if (sub3[i][1] == locationid){
document.all.s3.options[document.all.s3.length] = new Option(sub3[i][2], sub3[i][0]);
}
}
}
}
</script>
</head>

<body onload= "changeone( '1 ') ">
<select name=