0

我正在尝试从第二个选择中填充第二个下拉列表,但是每当我进行更改时,都没有更新。

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

<script>
var second_choice = $('#second-choice').val();
$("#first-choice").change(function() {
$("$second-choice").load("findModel.php?choice=" + $("#first-choice").val());
});
</script>

这是相关的 PHP 文件:

<?php
include 'dbc.php';

$choice = mysql_real_escape_string($_GET['choice']);

$query="SELECT * FROM `cars` WHERE `DVLAMake`='$choice'";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
    echo "<option>" . $row{'DVLAModel'} . "</option>";
}
?>

数据库连接有效。

...

<select id="first-choice">
<option selected value="base">Please Select a Make</option>
<?php 
$sql="SELECT DISTINCT `DVLAMake` FROM `cars`";
$result = mysql_query($sql);
while ($data=mysql_fetch_assoc($result))
{
echo "<option value =\"{$data[DVLAMake]}\" >{$data[DVLAMake]}</option>\n";
} 
?>
</select>

<select id="second-choice">
<option>Please choose from above</option>
</select>
<br />

<input type="submit" style="font-size:14px; padding:3;"value="Submit" size="20" />
</form>

...

有什么理由吗?

4

1 回答 1

4

你这里有错字$("$second-choice")

$("#second-choice").load("findModel.php?choice=" + $("#first-choice").val());

编辑 - 你试过了吗

$(function(){
    var second_choice = $('#second-choice').val();
    $("#first-choice").change(function() {
        $("$second-choice").load("findModel.php?choice=" + $("#first-choice").val());
    });
});
于 2012-04-05T10:00:45.767 回答