开发者

JQuery set cookies

How to save div title into cookies? And how to get this saved data, back?

<script type="text/javascript">
function setcookie(title, value, exp) {
    var expdate = new Date();
    expdate.setDate(开发者_运维知识库expdate.getDate() + exp);
    document.cookie = title+'='+value+';expires='+expdate.toGMTString()+';path=/';
}
</script>

<div title="1" onclick="setcookie();"></div>


See this question about jQuery and cookies. It will be easier to use a plug-in, like http://plugins.jquery.com/project/cookie.

Use following code to get the title of the div:

title = $("div").attr("title");


You may want to look into window.localStorage. It's very effective for what you are looking to do.

//Save the data
window.localStorage['mydiv'] = $('div').attr('title');

//Retrieve the data
$('div').attr('title', window.localStorage['mydiv']);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜