简体   繁体   English

用attr(href)设置jQuery cookie

[英]set jquery cookie with attr(href)

I have a script from this demo: tutorialzine.com 我有一个来自此演示的脚本: tutorialzine.com

As you can see the cookie is saved as plain text. 如您所见,cookie被保存为纯文本。 However I need it to be saved as a link. 但是,我需要将其另存为链接。 So I tried: 所以我尝试了:

// If the cookie has been set in a previous page load, show it in the div directly:
if(cookie) $('.jq-text').text(cookie).show();

    $('.fields a').click(function(e){

        var text = $('#inputBox').val();

// Setting a cookie with a seven day validity:

        $.cookie('demoCookie',text,{expires: 7, path: '/', domain: 'domain.com'});

            $('.jq-text').attr('href', text).html(text);

I don't know what exactly to change in order to 'attr' the 'var text' and save it as $cookie. 我不知道要“ attr”“ var text”并将其另存为$ cookie到底要更改什么。

please take a look at the demo: JsFiddle 请看一下演示: JsFiddle

The problem seems to be because of the variable "cookie". 问题似乎是由于变量“ cookie”。 Renaming it to "demoCookie" seems to fix the problem... 将其重命名为“ demoCookie”似乎可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM