所以我遇到了jQuery .not()函数的问题。
所有div通过切换正常崩溃,但问题在于关闭所有其他div类。如果你打开了第一个div,点击任何其他div会关闭它,但如果你先点击任何其他div,那么他们就不会关闭。
这是代码
function hideNot(id) {
$("#teamMemberDescription").not("." + id).hide();
}
$("#teamMember.paulturner").click(function(){
hideNot("paulturner");
$("#teamMemberDescription.paulturner").toggle(500);
});
$("#teamMember.paulblake").click(function(){
hideNot("paulblake");
$("#teamMemberDescription.paulblake").toggle(500);
});
$("#teamMember.bobhook").click(function(){
hideNot("bobhook");
$("#teamMemberDescription.bobhook").toggle(500);
});
$("#teamMember.yvonnemclean").click(function(){
hideNot("yvonnemclean");
$("#teamMemberDescription.yvonnemclean").toggle(500);
});
这是html
<div id="standardContainer" class="teamPage">
<div id="standardContent">
<h1 class="entry-title"><whiteblocker>MEET THE TEAM</whiteblocker></h1>
<div id="teamBanner">
<img src="<?php the_field('team_group_image');?>" width="100%">
</div>
<div id="teamDescription">
<h2>PREVENTEC - WHO WE ARE</h2>
<?php the_field('team_description');?>
</div>
<div id="teamMembers">
<?php if(get_field('team_members')): ?>
<?php while(the_repeater_field('team_members')): ?>
<?php $memberName = get_sub_field('member_name');?>
<?php $memberName = str_replace(" ","", $memberName);?>
<?php $memberName = strtolower($memberName);?>
<div id="teamMember" class="<?php echo $memberName;?>">
<img src="<?php the_sub_field('member_photo');?>">
<div class="teamMemberDetails">
<h3><?php the_sub_field('member_name');?></h3>
<h4><?php the_sub_field('member_position');?></h4>
</div>
</div>
<?php endwhile; ?>
<?php endif;?>
</div>
</div>
</div>
<div id="teamDetailsContainer">
<div id="teamDetailsContent">
<?php if(get_field('team_members')): ?>
<?php while(the_repeater_field('team_members')): ?>
<?php $memberName = get_sub_field('member_name');?>
<?php $memberName = str_replace(" ","", $memberName);?>
<?php $memberName = strtolower($memberName);?>
<div id="teamMemberDescription" class="<?php echo $memberName;?>">
<h1><?php the_sub_field('member_name');?></h1>
<?php the_sub_field('member_description');?>
</div>
<?php endwhile; ?>
<?php endif;?>
</div>
</div>
非常感谢任何帮助
答案 0 :(得分:-1)
猜测:你的结构应该是
// HTML
<div id="description">
<div id="paul">...</div>
<div id="...">...</div>
</div>
// JQUERY
function hideNot(name) {
$("#description > div").not("#" + name).hide();
}