【发布时间】:2016-09-30 13:31:09
【问题描述】:
我想在选择另一个列表的选项后更新列表
HTML 代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.5/css/bootstrap-select.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.5/js/bootstrap-select.min.js"></script>
<form action="check-add.php" method="post">
<table>
<tr>
<td align="center" height="60">students</span></td>
<td align="center" height="60"><select id="first-choice">
<option disabled selected>select students</option>
<option value="1">Mark</option>
<option value="2">Makarious</option>
</select></td>
</tr>
<tr>
<td align="center" height="60">subject</td>
<td align="center" height="60">
<select class="selectpicker" data-style="btn-info" multiple data-max-options="7" data-live-search="true" id="second-choice"></select>
</td>
</tr>
<tr>
<td align="center" height="100" colspan="2">
<input type="submit" class="but" name="save-students" value="add"/></td>
</tr>
</table>
</form>
JavaScript 代码
<script type="text/javascript">
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?choice=" + $("#first-choice").val());
}).trigger("change");
</script>
getter.php 文件
<?php
@include("../include/config.php");
$choice = @mysqli_real_escape_string($conn, $_GET['choice']);
$result = @mysqli_query($conn,"SELECT * FROM subjects WHERE phases='".$choice."'");
while($row = @mysqli_fetch_array($result, MYSQL_ASSOC)){
echo '<option value="'.$row['id'].'">'.$row['title'].'</option>';
}
?>
在此列表中选择变量后 不更新第二个列表 它没有出现选项 在#second-choice
我希望 JavaScript 代码自动更新第二个列表,但在从第一个菜单中选择选项后
【问题讨论】:
标签: javascript jquery select