jQuery:如果再次点击,请隐藏

时间:2010-08-29 10:40:21

标签: jquery

现在你点击一个链接,它发送ajax调用,并且成功时它会在输出中添加。不是我想,如果你点击链接打开它然后它应该关闭/隐藏输出。

function MoreFriendOptions(friend){
$.ajax({ 
       type: "POST",
       url: "misc/GetMoreFriend.php",
    data: {
    mode: 'ajax',
    friend : friend
    },
       success: function(msg){
      $('#MoreFriendInfo'+friend).prepend(msg);

        }
     });
}

echo "<div id='MoreFriendInfo".$showInfo['bID']."'></div>";
   <div style="float: right;">
  <a href="javascript:void(0);" onclick="MoreFriendOptions(<?=$showInfo["bID"];?>)">mer</a>
   </div>

2 个答案:

答案 0 :(得分:3)

你需要切换方法。

$('a.mylink').toggle(function() {
  //do your ajax stuff here
}, function() {
  //do your close and hide here
});

答案 1 :(得分:0)

如果你有类似

的设置
<div class=friends">
    <div class="friend1">John Doe</div>
    <div class="friend2">Jane Doe</div>
</div>

然后,如果保存定位索引,则可以删除/隐藏已添加的元素。

相关问题