Jquery只显示/隐藏但只有一个实例

时间:2011-01-26 13:19:05

标签: javascript jquery

我正在构建一个界面,当用户点击目标他们显示一个新菜单时,这个界面有这个目标的多个实例,每个目标显示相同的菜单,但是我只想显示下面的菜单目前已点击的目标,无论我点击的目标是什么,所有菜单都可见。

$('.statuses').hide();
$('.employer .status').click(function(e){
    alert('clicked');
    $('.employer .status').next('.statuses').show();
});

我的HTML

<div id="left-column">
<?php foreach($jobs as $j): ?>
<p><strong><?php echo $j['jobtitle']; ?></strong> &pound;<?php echo $j['salary']; ?>, <?php echo $j['job_summary']?> </p>
    <ul>
    <?php foreach($applications as $a): ?>
        <?php if ($j['jobtitle'] == $a['jobtitle']): ?>
            <li>
                <img src="/media/uploads/candidates/<?php echo preg_replace('/(.gif|.jpg|.png)/', '_thumb$1', $a['profile_image']);?>" width="90" height="60" alt="Hello"/>
                <p><?php echo $a['name']; ?></p>
                <p class="<?php echo $a['status'];?> status"><?php echo ucfirst($a['status']);?></p>
                <div class="statuses">
                    <p class="status pending"><a href="/employer/status/aid/<?php $a['id'];?>/pending">Pending</a></p>
                    <p class="status unsuccessful"><a href="/employer/status/aid/<?php $a['id'];?>/unsuccessful">Unsuccessful</a></p>
                    <p class="status successful"><a href="/employer/status/aid/<?php $a['id'];?>/successful">Successful</a></p>
                </div>
                <p class="date"><?php echo date("d.m.Y", $a['created_at']);?></p>
            </li>
        <?php endif; ?>
    <?php endforeach; ?>
 </ul>
<?php endforeach; ?>

1 个答案:

答案 0 :(得分:4)

$('.statuses').hide();
$('.employer .status').click(function(e){
    $(this).next('.statuses').show();
});