gpt4 book ai didi

php - 如何使用php创建多个依赖的下拉列表并将数据保存在mysql数据库中?

转载 作者:行者123 更新时间:2023-11-30 00:31:33 27 4
gpt4 key购买 nike

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "Content-Type" content = "text/html; charset=iso-8859-1" />
<title>Sections Demo</title>
<script type = "text/javascript" src = "http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".state").change(function()
{
var id = $(this).val();
var dataString = 'id=' + id;
$.ajax
({
type: "POST",
url: "ajax_city.php",
data: dataString,
cache: false,
success: function(html)
{
$(".district").html(html);
}
});
});
});
</script>
<style>
label
{
font-weight:bold;
padding:10px;
}
</style>
</head>

<body>
<div style="margin:80px">
<label>state :</label> <select name="country" class="country">
<option selected="selected">--Select state--</option>
<?php
include('db.php');
$sql = mysql_query("select id,data from states where weight='1'");



while ($row = mysql_fetch_array($sql)) {
$id = $row['id'];
$data = $row['data'];
echo '<option value="' . $id . '">' . $data . '</option>';
}
?>
</select> <br/><br/>
<label>district :</label> <select name="district" class="district">
<option selected="selected">--Select district--</option>
</select>
</div>
</body>
</html>

我正在尝试创建一个多个下拉列表,其中每个下拉列表都依赖于前一个下拉列表...例如:我想创建一个州的下拉列表,当选择一个州时,该州的地区应列在下一个下拉列表中,所选数据应存储在数据库中...任何人都可以帮我排序吗出去???提前谢谢...:-)

最佳答案

它不会返回 false,因为 ajax 方法是异步的,它不会等待成功事件发生。您可以通过使 ajax 同步

async: false

但这不是一个好方法。它也会卡住浏览器

关于php - 如何使用php创建多个依赖的下拉列表并将数据保存在mysql数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22475458/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com