search

Home  >  Q&A  >  body text

When I select the first item, two undefined appear

正确.png

This is a normal choice, if I have convulsions this will happen

错误.png

邓2378 days ago1658

reply all(6)I'll reply

  • ╰倒轉流年丶祇爲一眼紅顔

    ╰倒轉流年丶祇爲一眼紅顔2018-06-10 23:41:00

    Brother, can you show me the complete code of this part when you have time? I just can't get this effect right now. After looking at it for a long time, I still can't find any problem. Thank you very much.

    reply
    0
  • 邓

    Okay, you add me QQ908901178 and I will send it to you

    · 2018-06-11 08:02:39
  • 邓

    2018-05-12 08:49:02

    <!DOCTYPE html>

    <html>

    <head>

    <meta http-equiv="Content-Type" content=" text/html" charset="UTF-8">

    <title></title>

    <style type="text/css">

    #addr{width=60%;border-collapse:collpase;border:solid 1px Black;}

    #addr td,#addr th{

    border:1px solid Black;

    padding:3px 7px 2px 7px;

    }

    </style>

    The answer just now is missing some code at the beginning, please add it now.

    reply
    0
  • 邓

    2018-05-12 08:46:55

    I found the reason, it is region_action.php. When a null value is passed in, a flag=false msg="query type is wrong" and this json is returned.

    I removed the flag and only returned msg. Then Determine the value of msg when traversing json in region.html

    After the change, the source code of region.html is as follows:

    </style>

    <script src=". /jquery-2.2.3.js" type="text/javascript"></script>

    <script type="text/javascript">

    $(document ).ready(function() {

    // Load all provinces

    $.ajax({

    type: "get",

    url : "region_action.php", // type=1 means querying the province

    data: {"parent_id": "1", "type": "1"},

    dataType: " json",

    success: function(data) {

    $("#provinces").html("<option value=''>Please select a province</option> ");

                                                                                                                               .append("<option value='" + item.region_id + "'>" + item.region_name + "</option>");

          });

    }

    });

    // Load all cities in the current province

    $("#provinces").change(function() {

    $ ("#region").empty();

    $.ajax({

    type: "get",

    url: "region_action.php", // type =2 means querying the city

    data: {"parent_id": $(this).val(), "type": "2"},

    dataType: "json",

              success: function(data) {

                                                                                                                                                                                     

    ## $ ("#Countys"). Html ("& lt; option value = '' & gt; please select the county & lt;/option & gt;");

    ## $ .Each (data, function (Function i, item) {

    if(i!="msg"){

                      $("#citys").append("<option value='" + item.region_id + "'>" + item.region_name + "</option>");

                                                                                                                                                                                                  through

    ##       }

           });

        });

    // Load all counties in the current city

    $("#citys").change(function() {

    $ ("#region").empty(); ", // type =3 means querying the county

    data: {"parent_id": $(this).val(), "type": "3"},

    dataType: " json",

                                                                                                                                                                                    because ");

                                                                                              ).append("<option value='" + item.region_id + "'>" + item.region_name + "</option>");

              }else{

    ## });

    // Display address

    $("#countys").change(function() {

    $("#region").empty ();

    if($("#provinces").val()!="" && $("#citys").val()!="" && $("#countys") .val()!=""){

    var value = $("#provinces").find("option:selected").text()

                                                                                     cities").find("option:selected").text()

                      + $("#countys").find("option:selected").text();

      }else{

      var value ="The address you selected is incorrect ! ";

    }

    if($("#region")==""){

    $("#region").append("Selected The address is: "+"<input value='" + value + "'>");

    }else{

            $("#region").empty();

                                                                                                                     

    });

    });

    </script>

    </head>

    <body>

    <h1 align="left">Province, city and county three-level linkage</h1>

    <table id="addr">

    < tr bgcolor="skybule">

    <th>Province</th>

    <th>City</th>

    <th> County</th>

    </tr>

    <tr>

    <th>

    <select id="provinces ">

    <option value="">Please select a province</option>

    </select>

    </th>

    <th>

    <select id="citys">

    <option value="">Please select a city</option>

    </select>

    </th>

    <th>

    <select id="countys">

    <option value="">Please select a county</option>

    </select>

    </th>

    </tr> ;

    </table>

    <h4 align="left">

    <span id="region"></span>

    </h4>

    </body>

    </html>

    reply
    0
  • sky

    sky2018-05-11 17:16:41

    Do you have the source code?

    reply
    0
  • 邓

    It will be uploaded tomorrow, so it’s time to move a file in the tutorial

    · 2018-05-11 17:22:02
    邓

    源码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"> <title></title> <style type="text/css"> #addr{width=60%;border-collapse:collpase;border:solid 1px Black;} #addr td,#addr th{ border:1px solid Black; padding:3px 7px 2px 7px; } </style> <script src="./jquery-2.2.3.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { // 加载所有的省份 $.ajax({ type: "get", url: "region_action.php", // type=1表示查询省份 data: {"parent_id": "1", "type": "1"}, dataType: "json", success: function(data) { $("#provinces").html("<option value=''>请选择省份</option>"); $.each(data, function(i, item) { // alert(item.region_id); $("#provinces").append("<option value='" + item.region_id + "'>" + item.region_name + "</option>"); }); } }); // 加载当前省所有市 $("#provinces").change(function() { $("#region").empty(); $.ajax({ type: "get", url: "region_action.php", // type =2表示查询市 data: {"parent_id": $(this).val(), "type": "2"}, dataType: "json", success: function(data) { $("#citys").html("<option value=''>请选择市</option>"); $("#countys").html("<option value=''>请选择县</option>"); $.each(data, function(i, item) { $("#citys").append("<option value='" + item.region_id + "'>" + item.region_name + "</option>"); }); } }); }); // 加载当前市所有县 $("#citys").change(function() { $("#region").empty(); $.ajax({ type: "get", url: "region_action.php", // type =3表示查询县 data: {"parent_id": $(this).val(), "type": "3"}, dataType: "json", success: function(data) { $("#countys").html("<option value=''>Please select a county</option>"); $.each(data, function(i, item) { $("#countys").append("<option value='" + item.region_id + "'>" + item.region_name + "</option>"); }); } }); }); // display address $("#countys").change(function() { $("#region").empty(); if($("#provinces").val()!="" && $("#citys").val()!="" && $("#countys").val()!="") { var value = $("#provinces").find("option:selected").text() + $("#citys").find("option:selected").text() + $("#countys").find("option:selected").text(); }else{ var value="The address you selected is incorrect"; } if($("#region")==""){ $("#region").append("The selected address is: "+"<input value='" + value + "'>"); }else{ $("#region").empty(); $("#region").append("The selected address is: "+"<input value='" + value + "'>"); } }); }); </script> </head> <body> <h1 align="left">Three-level linkage between provinces, cities and counties</h1> <table id="addr"> <tr bgcolor="skybule"> <th>Province</th> <th>City</th> <th>County</th> </tr> <tr> <th> <select id="provinces"> <option value="">Please select a province</option> </select> </th> <th> <select id="citys"> <option value="">Please select a city</option> </select> </th> <th> <select id="countys"> <option value="">Please select a county</option> </select> </th> </tr> </table> <h4 align="left"> <span id="region"></span> </h4> </body> </html>

    · 2018-05-12 08:09:23
  • Cancelreply