将cookie值设置为递增int [英] Setting a cookie value to a incrementing int

查看:130
本文介绍了将cookie值设置为递增int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cookie有整数元素吗?我需要cookie增加10每次按下一个特定的按钮。

Is there a integer element for a cookie? I need the cookie to increment by 10 everytime a certain button is pushed. How can I start the cookie at 0 the first time and it's next value is based on it's current state.

document.cookie + = 10;

给出10,然后是1010,然后是101010.

我需要整数值 -

需要10,20,30等...

document.cookie += 10;
gives 10, then 1010, then 101010.
Right I dea but I need integer values-
Need 10, 20, 30, etc...

推荐答案

document.cookie = parseInt(document.cookie)+ 10;

document.cookie = parseInt(document.cookie) + 10;

您不应该信任原始Cookie数据或纯粹由javascript生成的数据,因为用户可以根据自己的需要对其进行修改。

Also, remember that you should never trust raw cookie data or data generated purely by javascript for anything serious as users can modify them as they see fit.

这篇关于将cookie值设置为递增int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆