当我单击div.info时,它需要再次隐藏/显示:无。
我怎样才能做到这一点?

html

<div class="floated">
<a href="#" class="showinfo">link 1</a>
<div class="info">onclick this div hide it again</div>
</div>


js

$(document).ready(function() {
    $("a.showinfo").click(function() {
        $("div.info").fadeOut();
        $(this).next("div.info").fadeIn();
    });
});


的CSS

div.info {
    display: none;
}
div.floated {
    float: left; position:relative; height:100px; width:100px; background:#f00;
}
div.info{
    position:absolute; background:#ccc; width:100px; height:100px; top:0;
}


小提琴:http://jsfiddle.net/KZ3Ky/6/

最佳答案

首先,您需要在第二个div上设置onClick函数,然后可以再次fadeOut div => DEMO

$(document).ready(function() {
 $("a.showinfo").click(function() {
    $("div.info").fadeOut();
    $(this).next("div.info").fadeIn();
     $("div.info").click(function(){
       $("div.info").css("display","none");
     });
  });
});

关于javascript - 用js重新隐藏内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17041328/

10-12 14:58
查看更多