可以jQuery读/写cookie到浏览器? [英] Can jQuery read/write cookies to a browser?
本文介绍了可以jQuery读/写cookie到浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单示例:我想在页面上有一些项目(如div或表行),我想让用户点击它们来选择它们。这似乎很容易在jQuery。要保存用户在没有服务器端回发的情况下点击的项目,我想一个cookie是一个简单的方法来完成这个。
Simple example: I want to have some items on a page (like divs or table rows), and I want to let the user click on them to select them. That seems easy enough in jQuery. To save which items a user clicks on with no server-side post backs, I was thinking a cookie would be a simple way to get this done.
- 这种假设是在这种情况下cookie是正确的,是否正确?
- 如果正确,jQuery API是否有一些方法来读/写cookie信息缺省JavaScript API?
推荐答案
用于设置Cookie的默认JavaScriptAPI简单为:
The default JavaScript "API" for setting a cookie is as easy as:
document.cookie = 'mycookie=valueOfCookie;expires=DateHere;path=/'
使用jQuery cookie插件,如:
Use the jQuery cookie plugin like:
$.cookie('mycookie', 'valueOfCookie')
这篇关于可以jQuery读/写cookie到浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文