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';
});