悟心

          成功不是將來才有的,而是從決定去做的那一刻起,持續(xù)累積而成。 上人生的旅途罷。前途很遠,也很暗。然而不要怕。不怕的人的面前才有路。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            93 隨筆 :: 1 文章 :: 103 評論 :: 0 Trackbacks
          <html>
          <head>
          <META http-equiv=Content-Type content="text/html; charset=gb2312">
          <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
          <script>
          (
          function($){
          $.fn.selInit 
          = function(){return $(this).html("<option>請選擇</option>");};
          $.area 
          = function(){
                  $(
          "#province").selInit();
                  $(
          "#city").selInit();
                  $(
          "#county").selInit();
                  
          var area = {
                          北京:{北京:
          "東城,西城,海淀,宣武,豐臺"},
                          江蘇:{南京:
          "江寧,六合,下關(guān),浦口",無錫:"北塘,濱湖,江陰,宜興"}
                          
          //
                  };
                  $.each(area,
          function(p){$("#province").append("<option>"+p+"</option>");});
                  $(
          "#province").change(function(){
                          $(
          "#city").selInit();
                          $(
          "#county").selInit();
                          $.each(area,
          function(p,x){
                                  
          if($("#province option:selected").text() == p)
                                  {
                                          $.each(x,
          function(c,cx){
                                                  $(
          "#city").append("<option>"+c+"</option>");
                                          });
                                          
                                          $(
          "#city").bind("change",function(){
                                                  $(
          "#county").selInit();
                                                  $.each(x,
          function(c,cx){
                                                          
          if($("#city option:selected").text() == c)
                                                                  {
                                                                          $.each(cx.split(
          ","),function(){
                                                                                  $(
          "#county").append("<option>"+this+"</option>");
                                                                          });
                                                                  }
                                                  });
                                          });
                                  }
                          });
                  });
          };
          })(jQuery);
          $(
          function(){
                  $(
          "select").css("width","100px");
                  $.area();
                  });
          </script>
          </head>
          <body>
              
          <select id="province"><option>請選擇</option></select>
                 
          <select id="city"><option>請選擇</option></select>
                 
          <select id="county"><option>請選擇</option></select>
          </body>
          </html>
          posted on 2010-07-17 12:52 艾波 閱讀(2451) 評論(2)  編輯  收藏 所屬分類: jquery

          評論

          # re: 利用jQuery聯(lián)動菜單制作 2014-09-25 16:08 N!ck
          謝謝博主的例子,看書上舉的each例子,看了半天也沒理解,后來看到博主的例子,一目了然!謝謝!  回復(fù)  更多評論
            

          # re: 利用jQuery聯(lián)動菜單制作 2016-01-16 13:50 uijkl
          guil  回復(fù)  更多評論
            

          主站蜘蛛池模板: 卢湾区| 鄯善县| 肥东县| 凌云县| 诸暨市| 曲靖市| 南岸区| 昔阳县| 桐乡市| 冷水江市| 和静县| 屏东县| 高淳县| 闻喜县| 灵宝市| 曲松县| 宜兰市| 康平县| 新乡市| 抚顺县| 江达县| 淄博市| 富裕县| 兴隆县| 靖西县| 彰武县| 三穗县| 淮南市| 新津县| 兴和县| 阳西县| 石林| 当阳市| 特克斯县| 山东省| 台湾省| 江阴市| 闽清县| 和龙市| 宾川县| 儋州市|