jquery操作cookie的方法

<a id="collect" href="javascript:void(0)"><span class="glyphicon glyphicon-heart" aria-hidden="true" style="display: inline-block;margin-left: 20px" title="在收藏中检索"></span></a>
<script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
   $(function(){
      var collect = $.cookie('collect');
      if(collect == 0){
         $("#collect").children('span').attr('style','display: inline-block;margin-left: 20px;');
      }else{
         $("#collect").children('span').attr('style','display: inline-block;margin-left: 20px;color: red');
      }
      $("#collect").bind("click",function(){
         var collect = $.cookie('collect');
         if(collect == 0){
            $.cookie('collect', '1');
            $("#collect").children('span').attr('style','display: inline-block;margin-left: 20px;color: red');
         }else{
            $.cookie('collect', '0');
            $("#collect").children('span').attr('style','display: inline-block;margin-left: 20px;');
         }

      })
   });
</script>

猜你喜欢

转载自blog.csdn.net/zhq_zvik/article/details/82744806
今日推荐