admin管理员组文章数量:1415139
I have this jquery: (jquery.cookie.js) And this is my cookie:
$(document).ready(function(){
//hide all divs just for the purpose of this example,
//you should have the divs hidden with your css
//$('.picture.1').hide();
//check if the cookie is already setted
if ($.cookie("currentDiv")===undefined){
$.cookie("currentDiv",1);
} else{ //else..well
//get and increment value, let's suppose we have just 8 divs
var numValue = parseInt($.cookie("currentDiv"));
numValue = numValue + 1;
if (numValue>8){
//restart to 1
$.cookie("currentDiv",1);
}
else{ //no issues, assign the incremented value
$.cookie("currentDiv",numValue.toString());
}
//show the div
$('.picture.'+$.cookie("currentDiv")).show(0);
}
});
The cookie called currentDiv has a number from 1 to 8 and changes every reload and reset when the value is higher as 8
How can I display the cookie (called currentDiv) with his current value? Like:
The installed cookies are:
currentDiv with the value (for example 5)
I have this jquery: https://github./carhartl/jquery-cookie (jquery.cookie.js) And this is my cookie:
$(document).ready(function(){
//hide all divs just for the purpose of this example,
//you should have the divs hidden with your css
//$('.picture.1').hide();
//check if the cookie is already setted
if ($.cookie("currentDiv")===undefined){
$.cookie("currentDiv",1);
} else{ //else..well
//get and increment value, let's suppose we have just 8 divs
var numValue = parseInt($.cookie("currentDiv"));
numValue = numValue + 1;
if (numValue>8){
//restart to 1
$.cookie("currentDiv",1);
}
else{ //no issues, assign the incremented value
$.cookie("currentDiv",numValue.toString());
}
//show the div
$('.picture.'+$.cookie("currentDiv")).show(0);
}
});
The cookie called currentDiv has a number from 1 to 8 and changes every reload and reset when the value is higher as 8
How can I display the cookie (called currentDiv) with his current value? Like:
The installed cookies are:
currentDiv with the value (for example 5)
Share
Improve this question
asked Apr 26, 2014 at 19:59
fdsugfhfdsugfh
5055 silver badges8 bronze badges
2 Answers
Reset to default 3you can do this to list all the pages cookies:
<span id="myId"><span>
<script>
document.getElementById('myId').innerHTML=listCookies()
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i-1] + "\n";
}
return aString;
}
</script>
jsfiddle:http://jsfiddle/5p34S/
Unless I am misunderstanding, create an element for the cookie value display, say its ID is "display-value".
Within the $(document).ready(function() { ... })
, add $("#display-value").text("The installed cookies are: currentDiv " + ($.cookie("currentDiv") || 0));
to the end (or to the beginning, depends on when you want to show it).
本文标签: javascriptHow to display the value of a cookie in a html fileStack Overflow
版权声明:本文标题:javascript - How to display the value of a cookie in a .html file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216180a2648180.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论