写个简单的例子  写一下注释   研究一下  谢了  各位大虾

解决方案 »

  1.   

    function college2subject(collegeid)
    {
    var allcount=0;
    subjectArray=new Array();
    <?php
    $link=mysql_connect("localhost","root","123");
             $db_selected=mysql_select_db("test");
     mysql_query("SET NAMES utf8");  
    $sql="select * from subject";
    $result=mysql_query($sql);
    $count=0;
    while($myrow=mysql_fetch_array($result))
      {
      
     echo "subjectArray[".$count."]=new Array('".$myrow['subject_id']."','".$myrow['subject_name']."',
    '".$myrow['college_id']."')\n";
    $count++;
    }
    echo "allcount=$count;";?>document.studentform.subject.length=0;
    document.studentform.subject.options[document.studentform.subject.length]=new Option("所有专业","");
    var college_id=collegeid;
    var i;
    for(i=0;i<allcount;i++)
    {
    if(subjectArray[i][2]==college_id)
    {
    document.studentform.subject.options[document.studentform.subject.length]=new Opiton(subjectArray[i][1],subjectArray[i][0]);
    alert("ok");
    }
    }
    }
    alert("ok");
    </script>
    </head><body>
    <?php
    $link=mysql_connect("localhost","root","123");
             $db_selected=mysql_select_db("test");
             mysql_query("SET NAMES utf8");

      $sql="select * from college";
     
      $result=mysql_query($sql)or die (mysql_error());
      
    ?><form id="studentform" name="studentform" method="post" action="">
    <table width="200" border="1">
      <tr>
        <td>请选择学院</td>
        <td>
          <label>
          <select name=college" onChange="college2subject(this.options[this.selectedIndex].value)">
            <option>所有学院</option>
     <?php
     while($myrow1=mysql_fetch_array($result))
      {
      ?> 
      <option value="<?php echo $myrow1["college_id"];?>" selected="selected">
      <?php echo $myrow1["college_name"];?></option>
           
            <?php } ?>
           
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>select筛选_water</title>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    </head>
    <body>
    <span>板块</span>
    <select name="water1" id = "water1">
      <option value="" selected>请选择</option>
      <option value="water1">water1</option>
      <option value="water2">water2</option>
      <option value="water3">water3</option>
      <option value="water4">water4</option>
      <option value="water5">water5</option>
    </select>
    <span>二级板块</span>
    <select name="water2">
      <option value="" selected>请选择</option>  <option value="water5-5" rel="water5">water5-5</option>
      <option value="water5-6" rel="water5">water5-6</option>
      <option value="water5-7" selected="selected">water5-7</option>
    </select>
    <script type="text/javascript">
    var $ = function(id){return document.getElementById(id);};(function(){    var dateop = {};    var manage = $('water2');    var options = manage.options;    for(var i=0;i<options.length;i++){        var rel = options[i].getAttribute('rel');        if(!rel) continue;        if(typeof dateop[rel] == 'undefined')  dateop[rel] = [];        dateop[rel].push({'value':options[i].value,'text':options[i].text});    };    $('water1').onchange = function(){change();};    function change(){        var type = $('water1').value;        var ttname = manage.value;        manage.options.length = 1;        if(type && typeof dateop[type]){            for(var i=0;i<dateop[type].length;i++){                manage.options.add(new  Option(dateop[type][i]['text'],                                    dateop[type][i]['value']));               if(manage.options[i].value == ttname){                    manage.options[i].selected = true               }            }        }else{            for(var j in dateop){                if(typeof dateop[j] != 'object') continue;                for(var i=0;i<dateop[j].length;i++){                    manage.options.add(new  Option(dateop[j][i]['text'],                                        dateop[j][i]['value']));                    if(manage.options[i].value == ttname){                         manage.options[i].selected = true                    }                }            }        }    }    change();})();</script>
    </body>
    </html>