![](/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.