我在具有动态下拉列表的项目中工作,该项目更改第二个数据取决于第一个数据,但我在其中遇到问题。来自3个文件的项目内容(索引.html,getcountry.php.script.js)
索引.html代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<select id="slctmake"></select></br>
<select id="slctmodel"></select>
<script src="jquery-1.10.2.js"></script>
<script src="script.js"></script>
</body>
</html>
获取国家.php代码
<?php
include "connect.php";
$query="SELECT DISTINCT country FROM `widgets` where country !='' ";
$data=mysqli_query($conn,$query);
$makes = array();
while($row=mysqli_fetch_array($data)){
array_push($makes,$row["country"]);
}
echo json_encode($makes);
?>
脚本.js代码
$(document).ready(function () {
$.getJSON("getcountry.php", success =function(data)
{
var options = "";
for (i=0 ; i < data.length ; i++ ){
options +="<option value '".data[i].tolowercase()+"'>"+data[i]+"'</option>";
}
$("#slctmake").append(options);
});
});
所以请伙计们可以帮助我解决我的问题,因为没有选择任何数据,并且我确信选择代码是正确的,因为我测试得很好
看看你的js代码:
options +="<option value '".data[i].tolowercase()+"'>"+data[i]+"'</option>"
;
您有语法错误,它应该是:
options +="<option value='"+data[i].tolowercase()+"'>"+data[i]+"</option>