gpt4 book ai didi

选择框的 javascript 函数不起作用

转载 作者:行者123 更新时间:2023-11-30 01:01:57 26 4
gpt4 key购买 nike

亲爱的大家,我是新人

该场景是根据第一个选择框的选择填充选择框,下面是我的代码

这部分代码填充mysql中的第一个选择框,当我从选择框中选择一个值时,jquery函数不会被触发,第二个选择框没有任何反应

<?php require_once("db_connect.php");?>
<?php require_once("functions.php");?>
<script type="text/javascript" src="jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".brands").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;

$.ajax
({
type: "POST",
url: "array_types.php",
data: dataString,
cache: false,
success: function(html)
{
$(".type").html(html);
}
});

});

});
</script>
<?php
echo "Country :
<select name=\"brands\" class=\"brands\">";
$brand_set=get_brands();
while($brand=mysqli_fetch_assoc($brand_set)){
echo "<option value=".$brand['brand_id'].">".$brand['brand_name']."</option>";
}
echo "</select> <br/><br/>
City :
<select name=\"type\" class=\"type\">
<option selected=\"selected\">--Select Type--</option>
</select>";
?>

这是我的 array_types.php

     <?php require_once("db_connect.php");?>
<?php require_once("functions.php");?>
<?php

if($_POST['id'])
{
$id=$_POST['id'];
$type_set=get_type_details($id);
while($type=mysqli_fetch_assoc($type_set)){
echo "<option value=".$type['prodtype_id'].">".$type['prod_type']."</option>";
}
}?>

functions.php 基本上是从 mysql DB 中收回记录请帮助我为什么第二个选择框没有被填充

问候

科德

最佳答案

明白了!在第 8 行 var dataString = 'id='+ id;我必须传递brand_id而不是id

关于选择框的 javascript 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20041482/

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