有一个 #filter div 包含 3 个选择:#dpmt_filter、#area_filter 和 #moi_filter。我无法让它将其他 2 个选择框(忽略当前选择框)“重置”为“全部”选项(这是顶部选项)。我认为它会是这样的:
$('#filters :input').not($(this)).val('all');
但它没有用。知道如何到达其他选择框并忽略当前吗?
jQuery(document).ready(function($){
$('#courses_listing div.accordion').addClass('active');
$('#filter :input').change(function(){
var current_value = $(this).val();
//$('#filters :input').not(current_value).val('all');
if(current_value=="all")
{
$('#courses_listing p').remove('.no-courses');
$('#courses_listing div.accordion').removeClass('hidden').addClass('active');
$('#filters :input').val('all');
}
else
{
if ($('#courses_listing').find('.accordion').hasClass('hidden')){
$('#courses_listing').find('.accordion').not('.' + $(this).val()).removeClass('active').addClass('hidden'); // changes other values from active to hidden.
$('#courses_listing').find('.accordion' + '.' + current_value).removeClass('hidden').addClass('active'); // changes selected value from hidden to active.
} else if ($('#courses_listing').find('.accordion').hasClass('active')){
$('#courses_listing').find('.accordion').not('.' + $(this).val()).removeClass('active').addClass('hidden'); // changes selected value from active to hidden.
}
if (!$('#courses_listing div.accordion').hasClass('active')) {$('#courses_listing div#filters').after('<p class="no-courses">There are no courses with the current filter.</p>');}
else{$('#courses_listing p').remove('.no-courses');}
}});
});
只是补充一下,这里是#filters div内的一个选择框的示例:
<div id="filters">
<div id="dpmt_filter">
<p>Select box 1</p>
<form action="<?php bloginfo('url'); echo $_SERVER["REQUEST_URI"]; ?>" method="get">
<?php // Grabs Department terms and displays them
$dpmts = get_terms('departments', array(
'orderby' => 'name',
'hide_empty' => 0
) );
?>
<select id="departments">
<option value="all">All</option>
<?php foreach ($dpmts as $dpmt) : ?>
<option value="<?php echo $dpmt->slug; ?>"><?php echo $dpmt->name; ?></option>
<?php endforeach; ?>
</select>
</form>
</div>
</div>