![](/img/trans.png)
[英]set attribute with .href and .attr('href') and jquery ID selectors
[英]set jquery cookie with attr(href)
我有一个来自此演示的脚本: tutorialzine.com
如您所见,cookie被保存为纯文本。 但是,我需要将其另存为链接。 所以我尝试了:
// 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);
我不知道要“ attr”“ var text”并将其另存为$ cookie到底要更改什么。
请看一下演示: JsFiddle
问题似乎是由于变量“ cookie”。 将其重命名为“ demoCookie”似乎可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.