mootools_使用MooTools创建,读取,更新和删除Cookies

mootools

MooTools features the ability to create, read, update, and delete cookies. Lets look at how we can use MooTools to control cookies.

MooTools具有创建,读取,更新和删除cookie的功能。 让我们看看如何使用MooTools来控制Cookie。

Cookie语法 (Cookie Syntax)

The syntax of the cookie, as laid out by the MooTools documentation, is:

根据MooTools文档的规定,cookie的语法为:

var myCookie = Cookie.write(key, value[, options]);

The options include:

选项包括:

  • domain: the domain for which the cookie will be written

    domain :将要写入Cookie的域

  • duration: the length, in days, that the cookie will last

    duration :cookie将持续的长度(以天为单位)

  • path: specific path the cookie belongs to

    path :cookie所属的特定路径

  • secure: a true/false value specifying if the cookie should be placed as secure

    secure :一个true / false值,指定是否应将cookie放置为安全

 

创建一个cookie (Creating a Cookie)


	var cookie  = Cookie.write('handle', 'SoccerStar23', {duration: 30, domain: '.davidwalsh.name'}); //save for a month


The above code creates a cookie that will last for 30 days at the root directory on the "davidwalsh.name" domain.

上面的代码创建了一个cookie,该cookie将在“ davidwalsh.name”域上的根目录中持续30天。

更新Cookie (Updating the Cookie)


	var cookie  = Cookie.write('handle', 'SoccerStar23', {duration: 1, secure: true}); //save for a month


You could delete and re-create the cookie, but why? You can simply overwrite its value and options.

您可以删除并重新创建cookie,但是为什么呢? 您可以简单地覆盖其值和选项。

读取Cookie (Reading a Cookie)


	var handle = Cookie.read('handle');


Reading the cookie is just as easy as creating one!

读取cookie就像创建一个cookie一样容易!

删除Cookie (Deleting a Cookie)


if(logoff) { Cookie.dispose('handle'); }


When it's time to remove the cookie manually, the above code works every time.

当需要手动删除cookie时,以上代码每次都会起作用。

So what would you use the MooTools Cookie for? How about saving text-size preferences? Also note that these cookies can be read by PHP too!

那么,您将使用MooTools Cookie做什么? 如何保存文本大小的首选项 ? 还请注意,PHP也可以读取这些cookie!

翻译自: https://davidwalsh.name/mootools-cookies

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值