jquery操作cookie的方法
阿新 • • 發佈:2018-11-05
<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>