zoukankan      html  css  js  c++  java
  • 前端记录cookie 点赞只能点一次

    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    }

    //取回cookie
    function getCookie(c_name)
    {
    if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end))
    }
    }
    return "";
    }

    实例:

    $(function () {
    var id = cid;
    var aa = getCookie('olid' + id);
    if (aa == id) {
    $('.num_right .right_2 i').addClass('dianzan');
    }
    $('.right_2').on('touchstart', function () {
    aa = getCookie('olid' + id);
    if (aa == id) {
    return false;
    }
    $.ajax({
    url: "http://api.devtool6.com/channels/like",
    type: "post",
    data: '{"APIDATA":{"cid":"' + cid + '","type":"2"}}',
    success: function (data) {

    $('.num_right .right_2 i').addClass('dianzan');

    $('.num_like').html($('.num_like').html()*1+1);
    setCookie('olid' + id, id, 365);
    },
    error: function () {
    $('.num_right .right_2 i').removeClass('dianzan1');
    }
    }
    );
    })
    });
    $('.users_right').on('click',function () {
    window.location.href='https://itunes.apple.com/us/app/i%E6%99%BA%E6%92%AD/id1225212114';
    });

  • 相关阅读:
    自动装配
    SpringMVC
    线程池的类型以及执行线程submit()和execute()的区别
    JDBC配置文件db.properties(Mysql) 及dbutils的编写
    tokuDB 安装与备份小记
    CentOS 7 安装 LEMP
    MySQL 闪回工具之 binlog2sql
    解决 MySQL 分页数据错乱重复
    ClickHouse 快速入门
    【理论篇】Percona XtraBackup 恢复单表
  • 原文地址:https://www.cnblogs.com/wplcc/p/7465991.html
Copyright © 2011-2022 走看看