JQuery Toggle 事件有记忆性的解决

 

$('#example').click(function(){$("#exampleBox").toggle();})
改为
$('#example').click(function(){
    if($("#exampleBox").is(":visible")){
        $("#exampleBox").hide();

    }else{
        $("#exampleBox").show();
    }
})

 第二种方式

$(".btn").on("click",function(){

    //通过判断按钮btn有没有active这个class名判断是否已经点击过
    if($(this).hasClass("active")){
    //如果有了active,假设已经点击过了
    //执行你的代码
    //把active去掉
    $(this).removeClass("active");
    }else{
    //没有active,假设还没有点击过
    //执行你的代码
    $(this).addClass("active");
    }
})

待更新。。。。

posted @ 2015-11-01 11:23  QuincySx  阅读(196)  评论(0编辑  收藏  举报