我的逻辑是建立一个图书馆管理系统,在该系统中,它首先要求学生分类名称,而不是选择中级(数据库中为1)然后显示中级组别,如果选择了BS而不是显示BS部门。
<?php
require '/include/connect.inc.php';
require '/include/core.inc.php';
?>
<script type="text/javascript" src="include/JS/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="include/JS/jQuery.js"></script>
<style>tr.Department_Options{ display: none; }</style>
<div class="articles">
<form method="POST" action="#">
<table align="center">
<tr><th><label for="ChoosedClassID">Class : </label></th><td><select name="ChoosedClassID" id="ChoosedClassID"><option disabled selected>Select Class :</option><?php
$query="SELECT ClassID,ClassName from class ORDER BY ClassName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
$ClassName=$catch['ClassName'];
$ClassID=$catch['ClassID']; ?>
<option value="<?php echo $ClassID;?>"><?php echo $ClassName; ?></option>
<?php } ?></select><br></td></tr>
<tr id="tr_A" class="Department_Options"><th><label for="id_A">Choose Your Group : </label></th><td><select name="InterGroupID" id="InterGroupID"><option disabled selected>Intermediate Group :</option><?php
$query="SELECT DID,DepartmentName from department WHERE ClassID=1 ORDER BY DepartmentName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
$DepartmentName=$catch['DepartmentName'];
$DID=$catch['DID']; ?>
<option value="<?php echo $DID;?>"><?php echo $DepartmentName; ?></option>
<?php } ?></select><br></td></tr>
<tr id="tr_B" class="Department_Options"><th><label for="id_B">Choose Department : </label></th><td><select name="DepartmentName" id="DepartmentName"><option disabled selected>BS Department Name</option><?php
$query="SELECT DID,DepartmentName from department WHERE ClassID=2 ORDER BY DepartmentName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
$DepartmentName=$catch['DepartmentName'];
$DID=$catch['DID']; ?>
<option value="<?php echo $DID;?>"><?php echo $DepartmentName; ?></option>
<?php } ?></select><br></td></tr>
</table>
</form>
</div>
jQuery.js文件
$(document).ready(function(){
$('#ChoosedClassID').on('change', function() {
$('tr.Department_Options').hide();
$('#tr_' + $(this).val() ).show();
});
});
根据上面的代码,当我选择BS,Intermediate,Next Drop Down Meny不会出现。
我想要的是显示下拉菜单,当我从中选择一些值时,它应该询问学生资料库编号,然后我想进行插入查询。
答案 0 :(得分:0)
您是否在JavaScript中尝试了一些调试?将临时alert()
语句放入,因此:
$(document).ready(function(){
alert(1);
$('#ChoosedClassID').on('change', function() {
alert(2);
$('tr.Department_Options').hide();
$('#tr_' + $(this).val() ).show();
});
});
你得到&#34; 1&#34;在页面加载和&#34; 2&#34;关于控制变更事件?这是你需要做的第一件事。如果你这样做,你可能会继续查看$(this).val()
以查看解决的价值。
正如我在评论中所述,如果弹出任何JavaScript错误,请务必检查浏览器的控制台。另外,请检查您的网络面板,以确保正确加载外部JavaScript资源(特别是jQuery)。