首页>>表单>>普通php二级联动菜单,级联菜单(2013-09-10)

普通php二级联动菜单,级联菜单

 数据库结构与ajax php二级联动菜单相同

普通php二级联动菜单,级联菜单
赞赏支持
立刻微信赞赏支持 关闭

代码

 

PHP Code
  1. <script language = "JavaScript">  
  2. var onecount;  
  3. onecount=0;  
  4. subcat = new Array();  
  5. <?  
  6. //类别选择  
  7. mysql_select_db($database_lr$lr);  
  8. $sql = "select * from smallclass";  
  9. $result = mysql_query( $sql );  
  10. $count = 0;  
  11. while($res = mysql_fetch_row($result)){  
  12. ?>  
  13. subcat[<?=$count?>] = new Array("<?=$res[0]?>","<?=$res[1]?>","<?=$res[2]?>");  
  14. <?  
  15. $count++;  
  16. }  
  17. echo "onecount=$count;";  
  18. ?>  
  19. function changelocation(locationid)  
  20.     {  
  21.     document.myform.smallclassid.length = 0;   
  22.     var locationid=locationid;  
  23.     var i;  
  24.     for (i=0;i < onecount; i++)  
  25.         {  
  26.             if (subcat[i][2] == locationid)  
  27.             {   
  28.        //var newOption1=new Option(subcat[i][1], subcat[i][0]);  
  29.                 //document.all.smallclassid.add(newOption1);  
  30.                 document.myform.smallclassid.options[document.myform.smallclassid.length] = new Option(subcat[i][1], subcat[i][0]);  
  31.             }          
  32.         }  
  33.           
  34.     }      
  35. </script>  
  36. <h1 class="logo"><a href="http://www.freejs.net" title="freejs首页"><img src="../../images/logo.png" height="47" width="500" alt="freejs首页" /></a></h1>  
  37. <div id="main_demo">  
  38. <div align="center"><h2><a href="http://www.freejs.net/article_biaodan_30.html">普通php二级联动菜单,级联菜单</a></h2></div>  
  39. <form method="post" name="myform" action="" onSubmit="return CheckForm();" style="text-align:center">  
  40. 选择类别:<select name="bigclassid" onChange="changelocation(document.myform.bigclassid.options[document.myform.bigclassid.selectedIndex].value)" size="1">  
  41. <option selected value="">选择大类</option>  
  42.           
  43.  <?  
  44.    $sql = "select * from bigclass order by sort";  
  45.    $result = mysql_query( $sql );  
  46.    while($res = mysql_fetch_row($result)){  
  47.  ?>  
  48.     <option value="<? echo $res[0]; ?>"><? echo $res[1]; ?></option>  
  49.   <? } ?>  
  50.           
  51.        </select>   
  52.       
  53.     <select name="smallclassid">                    
  54.         <option selected value="">选择小类别</option>  
  55.     </select>  
  56.     </form>  

 


原文地址:http://www.freejs.net/article_biaodan_30.html