[英]jQuery - List result based on dropdown option selection
Please review my Demo Fiddle 请查看我的演示小提琴
If you select an option from a menu, it will match up with another corresponding option. 如果从菜单中选择一个选项,它将与另一个相应的选项匹配。
In the first menu, if you select a type of exam, it will match up with an appropriate course result. 在第一个菜单中,如果您选择某种类型的考试,它将与相应的课程结果相匹配。
Additionally, the second menu allows you to select a course, and the appropriate exam result will be displayed. 此外,第二个菜单允许您选择课程,并将显示相应的考试结果。
For example - If you select American Literature or Introduction to Educational Psychology , the result displayed is Free Elective 例如 - 如果您选择美国文学或教育心理学简介 ,则显示的结果是自由选择
However, if in the menu below, you select Free Elective , the only course that comes up is American Literature , and not the other Introduction to Educational Psychology . 但是,如果在下面的菜单中选择Free Elective ,那么唯一的课程就是美国文学 ,而不是其他的教育心理学导论 。
How can I select Free Elective and have it display a list of classes associated, and not just one? 如何选择Free Elective并让它显示相关的类列表,而不仅仅是一个?
Here is my JS ... 这是我的JS ......
$(function() {
$('#clepSelector').change(function(){
$('.class').hide();
$('#' + $(this).val()).fadeIn();
});
});
$(function() {
$('#classSelector').change(function(){
$('.clep').hide();
$('#' + $(this).val()).fadeIn();
});
});
To begin with, you cannot have duplicate IDs in the DOM. 首先,您不能在DOM中拥有重复的ID。
So, remove free_elective
as an id
& make it a class
. 因此,删除
free_elective
作为id
并使其成为一个class
。
HTML HTML
<div class="clep free_elective" style="display: none"> American Literature </div>
<div class="clep free_elective" style="display: none"> Introduction to Educational Psychology </div>
jQuery jQuery的
$('#classSelector').change(function(){
$('.clep').hide();
$('.' + $(this).val()).fadeIn();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.