無線&移動互聯網技術研發

          換位思考·····
          posts - 19, comments - 53, trackbacks - 0, articles - 283
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
          呵,其實有些時候要求的沒那么嚴格的話,用JS就能搞定了。我從網上找了一段,
          <form name="frm">
          <select name="s1" onChange="redirec(document.frm.s1.options.selectedIndex)">
          <option selected>請選擇</option>
          <option value="1">腳本語言</option>
          <option value="2">高級語言</option>
          <option value="3">其他語言</option>
          </select>

          <select name="s2">
          <option value="請選擇" selected>請選擇</option>
          </select>
          </form>

          <script language="javascript">
          //獲取一級菜單長度
          var select1_len = document.frm.s1.options.length;
          var select2 = new Array(select1_len);

          //把一級菜單都設為數組
          for (i=0; i<select1_len; i++){
              select2[i] 
          = new Array();
          }


          //定義基本選項
          select2[0][0= new Option("請選擇"" ");

          select2[
          1][0= new Option("PHP"" ");
          select2[
          1][1= new Option("ASP"" ");
          select2[
          1][2= new Option("JSP"" ");

          select2[
          2][0= new Option("C/C++"" ");
          select2[
          2][1= new Option("Java"" ");
          select2[
          2][2= new Option("C#"" ");

          select2[
          3][0= new Option("Perl"" ");
          select2[
          3][1= new Option("Ruby"" ");
          select2[
          3][2= new Option("Python"" ");

          //聯動函數
          function redirec(x){
              
          var temp = document.frm.s2; 
              
          for (i=0;i<select2[x].length;i++){
                  temp.options[i]
          =new Option(select2[x][i].text,select2[x][i].value);
              }

              temp.options[
          0].selected=true;
          }


          </script>


          像這種常見的就是省--市--縣等的聯動了。那個網上一大堆,也幸苦那些作者了。
          主站蜘蛛池模板: 蕉岭县| 枣阳市| 阜南县| 平塘县| 屏山县| 莆田市| 玛纳斯县| 襄城县| 正镶白旗| 元阳县| 屏边| 孟津县| 龙门县| 张家口市| 宁城县| 寿宁县| 伊川县| 新余市| 灵璧县| 沁水县| 德清县| 河间市| 介休市| 囊谦县| 隆回县| 吉水县| 论坛| 华蓥市| 梧州市| 嘉荫县| 咸阳市| 讷河市| 六盘水市| 青田县| 桂林市| 化隆| 望都县| 万源市| 个旧市| 商南县| 根河市|