动态链接两个下拉菜单

时间:2018-10-11 04:57:37

标签: jquery html json

//This is the html page


<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
   <div id="container">
        <select id="officeType">
          <option value="">OfficeList</option>
          <option value="ministryDiv">Ministry</option>
          <option value="divisionBatayon">Division</option>
       </select>

       <select id="ministryList"></select>
    </div>   
   <script>
      var $select = $('#ministryList');
      $.getJSON('all-ministry-list.JSON',function(value){
          $select.html('');

          for(var i=0;i<value['data'].length;i++){
             $select.append('<option id="' +value['data'][i]['id'] +'">' +value['data'][i]['sitename_bn'] +'</option>');
          }
      });
   </script>

</body>
</html>

//这是all-ministry-list.JSON文件

{
    "data": [

        {
            "id": "6484",
            "subdomain": "mohpw.portal.gov.bd",
            "sitename_en": "Ministry of Housing and Public Works",
            "sitename_bn": "গৃহায়ণ ও গণপূর্ত মন্ত্রণালয়",
            "weight": "99999"
        },
        {
            "id": "6487",
            "subdomain": "minland.portal.gov.bd",
            "sitename_en": "Ministry Of Land",
            "sitename_bn": "ভূমি মন্ত্রণালয়",
            "weight": "99999"
        }

    ]
}
//this is the ministry-child-list.JSON file
{
    "data": [
        {
            "id": "6209",
            "subdomain": "beza.portal.gov.bd",
            "sitename_en": "Bangladesh Economic Zones Authority",
            "sitename_bn": "বাংলাদেশ অর্থনৈতিক অঞ্চল কর্তৃপক্ষ",
            "weight": "99999"
        },
        {
            "id": "6218",
            "subdomain": "ngoab.portal.gov.bd",
            "sitename_en": "NGO Affairs Bureau",
            "sitename_bn": "এনজিও বিষয়ক ব্যুরো",
            "weight": "99999"
        },
        {
            "id": "6558",
            "subdomain": "bida.portal.gov.bd",
            "sitename_en": "Bangladesh Investment Development Authority (BIDA)",
            "sitename_bn": "বাংলাদেশ বিনিয়োগ উন্নয়ন কর্তৃপক্ষ",
            "weight": "99999"
        }
    ]
}

这里有两个下拉菜单。在第一个下拉菜单中,我手动给出了option的值。在第二个下拉菜单中,我从json文件中获得了option的值。现在我想将这两个下拉列表连接在一起。我想在第二个下拉列表ministryList中看到json文件all-ministry-list.json的值,当我单击Division时,我想在第二个下拉列表ministryList中看到json文件ministry-child-list.json的值。连接这两个表?plz帮助

0 个答案:

没有答案