When I select the first item, two undefined appear
邓
2018-05-11 16:45:28
0
6
1665

正确.png

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

错误.png

邓

reply all(4)
╰倒轉流年丶祇爲一眼紅顔

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 Okay, you add me QQ908901178 and I will send it to you
    author 2018-06-11 08:02:39
邓

<!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.

邓

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&gt ;

</table>

<h4 align="left">

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

</h4>

</body>

</html>

sky

Do you have the source code?

  • reply It will be uploaded tomorrow, so it’s time to move a file in the tutorial
    author 2018-05-11 17:22:02
  • reply 源码如下: &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html" charset="UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;style type="text/css"&gt; #addr{width=60%;border-collapse:collpase;border:solid 1px Black;} #addr td,#addr th{ border:1px solid Black; padding:3px 7px 2px 7px; } &lt;/style&gt; &lt;script src="./jquery-2.2.3.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(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("&lt;option value=''&gt;请选择省份&lt;/option&gt;"); $.each(data, function(i, item) { // alert(item.region_id); $("#provinces").append("&lt;option value='" + item.region_id + "'&gt;" + item.region_name + "&lt;/option&gt;"); }); } }); // 加载当前省所有市 $("#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("&lt;option value=''&gt;请选择市&lt;/option&gt;"); $("#countys").html("&lt;option value=''&gt;请选择县&lt;/option&gt;"); $.each(data, function(i, item) { $("#citys").append("&lt;option value='" + item.region_id + "'&gt;" + item.region_name + "&lt;/option&gt;"); }); } }); }); // 加载当前市所有县 $("#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("&lt;option value=''&gt;Please select a county&lt;/option&gt;"); $.each(data, function(i, item) { $("#countys").append("&lt;option value='" + item.region_id + "'&gt;" + item.region_name + "&lt;/option&gt;"); }); } }); }); // 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: "+"&lt;input value='" + value + "'&gt;"); }else{ $("#region").empty(); $("#region").append("The selected address is: "+"&lt;input value='" + value + "'&gt;"); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 align="left"&gt;Three-level linkage between provinces, cities and counties&lt;/h1&gt; &lt;table id="addr"&gt; &lt;tr bgcolor="skybule"&gt; &lt;th&gt;Province&lt;/th&gt; &lt;th&gt;City&lt;/th&gt; &lt;th&gt;County&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; &lt;select id="provinces"&gt; &lt;option value=""&gt;Please select a province&lt;/option&gt; &lt;/select&gt; &lt;/th&gt; &lt;th&gt; &lt;select id="citys"&gt; &lt;option value=""&gt;Please select a city&lt;/option&gt; &lt;/select&gt; &lt;/th&gt; &lt;th&gt; &lt;select id="countys"&gt; &lt;option value=""&gt;Please select a county&lt;/option&gt; &lt;/select&gt; &lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;h4 align="left"&gt; &lt;span id="region"&gt;&lt;/span&gt; &lt;/h4&gt; &lt;/body&gt; &lt;/html&gt;
    author 2018-05-12 08:09:23
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template