亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery實(shí)現(xiàn)的省市區(qū)三級(jí)聯(lián)動(dòng)

 更新時(shí)間:2015年04月02日 09:07:35   投稿:hebedich  
在做項(xiàng)目的時(shí)候,我們經(jīng)常需要用到地址之類的省市區(qū)三級(jí)聯(lián)動(dòng)的,今天就給大家分享一個(gè)非常簡(jiǎn)潔的省市區(qū)三級(jí)聯(lián)動(dòng)的代碼,基于jQuery,附上GIT地址,有需要的小伙伴可以直接拿走

省市級(jí)聯(lián)動(dòng),附使用示例和數(shù)據(jù)表數(shù)據(jù)

有部分?jǐn)?shù)據(jù)精確到鄉(xiāng)鎮(zhèn)一級(jí)!??!

Git 地址:http://git.oschina.net/upliu/province-city-district

演示代碼:

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>省市區(qū)三級(jí)聯(lián)動(dòng)</title>
</head>
<body>
<form method="post" action="post.php">
  <div id="area"></div>
  <input type="submit" style="margin-top: 10px;">
</form>
<script src="jquery-2.1.3.min.js"></script>
<script src="area.js"></script>
<script>
  $(function(){
 
    add_select(0);
 
    $('body').on('change', '#area select', function() {
      var $me = $(this);
      var $next = $me.next();
      /**
       * 如果下一級(jí)已經(jīng)是當(dāng)前所選地區(qū)的子地區(qū),則不進(jìn)行處理
       */
      if ($me.val() == $next.data('pid')) {
        return;
      }
      $me.nextAll().remove();
      add_select($me.val());
    });
 
    function add_select(pid) {
      var area_names = area['name'+pid];
      if (!area_names) {
        return false;
      }
      var area_codes = area['code'+pid];
      var $select = $('<select>');
      $select.attr('name', 'area[]');
      $select.data('pid', pid);
      if (area_codes[0] != -1) {
        area_names.unshift('請(qǐng)選擇');
        area_codes.unshift(-1);
      }
      for (var idx in area_codes) {
        var $option = $('<option>');
        $option.attr('value', area_codes[idx]);
        $option.text(area_names[idx]);
        $select.append($option);
      }
      $('#area').append($select);
    };
  });
</script>
</body>
</html>

以上所述就是本文給大家分享的全部?jī)?nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論