关联菜单!
给楼主一段代码,仔细分析一下就知道其中的奥妙了!<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();arrItems1[3] = "Truck";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Train";
arrItemsGrp1[4] = 1;
arrItems1[5] = "Car";
arrItemsGrp1[5] = 1;arrItems1[6] = "Boat";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Submarine";
arrItemsGrp1[7] = 2;arrItems1[0] = "Planes";
arrItemsGrp1[0] = 3;
arrItems1[1] = "Ultralight";
arrItemsGrp1[1] = 3;
arrItems1[2] = "Glider";
arrItemsGrp1[2] = 3;var arrItems2 = new Array();
var arrItemsGrp2 = new Array();arrItems2[21] = "747";
arrItemsGrp2[21] = 0
arrItems2[22] = "Cessna";
arrItemsGrp2[22] = 0arrItems2[31] = "Kolb Flyer";
arrItemsGrp2[31] = 1
arrItems2[34] = "Kitfox";
arrItemsGrp2[34] = 1arrItems2[35] = "Schwietzer Glider";
arrItemsGrp2[35] = 2arrItems2[99] = "Chevy Malibu";
arrItemsGrp2[99] = 5
arrItems2[100] = "Lincoln LS";
arrItemsGrp2[100] = 5
arrItems2[57] = "BMW Z3";
arrItemsGrp2[57] = 5arrItems2[101] = "F-150";
arrItemsGrp2[101] = 3
arrItems2[102] = "Tahoe";
arrItemsGrp2[102] = 3arrItems2[103] = "Freight Train";
arrItemsGrp2[103] = 4
arrItems2[104] = "Passenger Train";
arrItemsGrp2[104] = 4arrItems2[105] = "Oil Tanker";
arrItemsGrp2[105] = 6
arrItems2[106] = "Fishing Boat";
arrItemsGrp2[106] = 6arrItems2[200] = "Los Angelas Class";
arrItemsGrp2[200] = 7
arrItems2[201] = "Kilo Class";
arrItemsGrp2[201] = 7
arrItems2[203] = "Seawolf Class";
arrItemsGrp2[203] = 7function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
  var myEle ;
  var x ;
  // Empty the second drop down box of any choices
  for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
  if (control.name == "firstChoice") {
    // Empty the third drop down box of any choices
    for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
 }
  // ADD Default Choice - in case there are no values
  myEle = document.createElement("option") ;
  myEle.value = 0 ;
  myEle.text = "[SELECT]" ;
  controlToPopulate.add(myEle) ;
for ( x = 0 ; x < ItemArray.length  ; x++ )
    {
      if ( GroupArray[x] == control.value )
        {
          myEle = document.createElement("option") ;
          myEle.value = x ;
          myEle.text = ItemArray[x] ;
          controlToPopulate.add(myEle) ;
        }
    }
}
//  End -->
</script>
<form name=myChoices>
<table align="center">
<tr>
<td>
<SELECT id=firstChoice name=firstChoice onchange="selectChange(this, myChoices.secondChoice, arrItems1, arrItemsGrp1);">
    <option value=0 SELECTED>[SELECT]</option>
    <option value=1>Land</option>
    <option value=2>Sea</option>
    <option value=3>Air</option>
</SELECT>
</TD><TD>
<SELECT id=secondChoice name=secondChoice onchange="selectChange(this, myChoices.thirdChoice, arrItems2, arrItemsGrp2);">
</SELECT>
<SELECT id=thirdChoice name=thirdChoice>
</SELECT>
</TD>
</TR>
</TABLE>
</form>

解决方案 »

  1.   

    <script language="javascript">
    <!--
    function ctxt(value)
    {
    var obj=document.all.list2.options;
    var len=obj.length;
    for(i=0;i<len;i++)
    obj.remove(0);
    for (i=1;i<=5;i++)
    obj.add(new Option(value+i,value+i,true,true));
    }
    -->
    </script>
    <select name="list1" onchange="ctxt(this.value)">
    <option value=a>a</option>
    <option value=b>b</option>
    <option value=c>c</option>
    <option value=d>d</option>
    <option value=e>e</option>
    <option value=f>f</option>
    </select>
    <select name="list2">
    <option value=a1>a1</option>
    <option value=a2>a2</option>
    <option value=a3>a3</option>
    <option value=a4>a4</option>
    <option value=a5>a5</option>
    <option value=a6>a6</option>
    </select>
      

  2.   

    这个是叫 无刷新2级连动 一般用JSCRIPT 实现.不过当你需要从数据库得到内容的时候。就需要写一些东西了.我给你个参考代码吧/*本函数是一个2级联动的函数,利用JSCRIPT 实现了无刷新联动,这个函数可以同时做插入或者更新的需求。*/  代码测试完毕。上次版本有的错误已经修改。并封装成函数。 
    --------------------------------------------------------------------------------function this_form($Sid,$Bid,$S_fieldName,$Sclass){global $DB;
    echo "<script language=javascript>\n";
    echo "function StreetIdName(sid,sname)\n";
    echo "{\n";
    echo " this.id=sid;\n";
    echo " this.name=sname\n";
    echo "}\n";
    echo "function changeZip(frm)\n";
    echo "{\n";
    echo " frm.streetid.length = 1;\n";
    echo " if(frm.zipcodeid.value != \"\")\n";
    echo " {\n";
    echo "  for(i=0; i<street.length; i++)\n";
    echo "  {\n";
    echo "   if(frm.zipcodeid.value == street[i][0])\n";
    echo "   {\n";
    echo "    for(j=1; j<street[i].length; j++)\n";
    echo "    {\n";
    echo "     frm.streetid.length++;\n";
    echo "     frm.streetid[j].value = street[i][j].id;\n";
    echo "     frm.streetid[j].text = street[i][j].name;\n";
    echo "    }\n";
    echo "    break;\n";
    echo "   }\n";
    echo "  }\n";
    echo " }\n";
    echo "}\n";//select 二级类的ID,大类的ID,二级类的中名名称, FROM 二级类表名,ORDER BY 大类的ID,二级类的中文名称
    $selectStreetSql = "select ".$Sid.",".$Bid.",".$S_fieldName." from ".$Sclass." order by ".$Bid.",".$S_fieldName."";//$selectStreetSql = "select * from "" order by channel_id,second_name";
    $resultStreet    = $DB->query($selectStreetSql);
     $totalStreet = $DB->num_rows($resultStreet);
     $streetCount = 0;
     $zipCount = -1;
     $currentZipcode = -1;
     $jsZipAndStreet = "var street = new Array();\n";
     
     for($i = 0; $i < $totalStreet; $i++)
     {
      $rowStreet = $DB->fetch_array($resultStreet);
      if($currentZipcode != $rowStreet[1])
      {
       $currentZipcode = $rowStreet[1];
       $zipCount++;
       $streetCount = 0;
       $jsZipAndStreet .= "street[$zipCount]= new Array();\n street[$zipCount][0]=".$rowStreet[1].";\n";
      }
      $streetCount++;
      $jsZipAndStreet .= "street[$zipCount][$streetCount] = new StreetIdName(".$rowStreet[0].",\"".$rowStreet[2]."\");\n";
     }
    echo $jsZipAndStreet;echo "</script>\n";}function city_street($Bclass,$Bid,$B_fieldName,$B_inValue,$Sclass,$Sid,$S_fieldName,$S_inValue){
    // 大类的表名: $Bclass    大类的ID名:$Bid   大类的字段名:$B_fieldName   带入大类的值 $B_inValue
    // 二类的表名: $Sclass    二类的ID 名 $Sid     字段名:$S_fieldName          代入的值    $S_inValue
    global $DB;
    echo " 
         <select name='zipcodeid' onchange='JavaScript: changeZip(this.form);'>
         <option value=''>-请选择-</option>
         ";
         
       $Sql="select * from ".$Bclass." order by ".$Bid." asc";   
          $Query = $DB->query($Sql);
          $Num   = $DB->num_rows($Query);      if ( 0 < $Num ){       while ( $Result = $DB->fetch_array( $Query ) ) {        echo "<option value=".$Result[$Bid]." "; 
              if ($Result[$Bid] == $B_inValue) { 
             echo " selected  "; 
        }
      echo "  > ".$Result[$B_fieldName]."</option>\n";
      
           }
         } echo "
          </select>      
       
       
       <select name='streetid' id='streetid'>
          <option value=''>--请选则--</option>
          ";        if ($B_inValue!='' && $S_inValue!=''){
       
       $Sql="select * from ".$Sclass." where ".$Bid."=".$B_inValue;   
          $Query = $DB->query($Sql);
          $Num   = $DB->num_rows($Query);        if ( 0 < $Num ){           while ( $Result = $DB->fetch_array( $Query ) ) {             echo "<option value=".$Result[$Sid]." "; 
                   if ($Result[$Sid] == $S_inValue) { 
                  echo " selected  "; 
          }
            echo "  > ".$Result[$S_fieldName]."</option>\n";  
               }
            }
       }     
      
         echo "
       </select>
              ";}
      

  3.   

    调用演示:/*在文件头部打印出JSCRIPT*/
    <?=$FUNCTIONS->this_form("item_id","strong_id","item_name","strong_item");?>
    /*显示2级联SELECT单*/
    <?=$FUNCTIONS->city_street('strong_class','strong_id','strong_name',$strong_id,'strong_item','item_id','item_name',$item_id);?>    演示地址:http://www.tjsohu.com/news/autocar//* 这个是很久前写的了.你自己看看吧.还有现在尽量不要用ECHO 直接在函数里返回.这样不好.将来用摸版的时候你就知道了.自己看看吧.这个当初也让我郁闷了好几天,希望我能帮助到你!!!*/
      

  4.   

    我有无限级的,PHP+MYSQL+JS+XML版本的,但是是集合在我的类里面!不太容易分离!
    等我有空分离出来给你们吧!