gpt4 book ai didi

javascript - 如何在 .html 文件中显示 cookie 的值

转载 作者:行者123 更新时间:2023-11-30 12:43:54 32 4
gpt4 key购买 nike

我有这个 jquery:https://github.com/carhartl/jquery-cookie (jquery.cookie.js)这是我的 cookies :

$(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);
}
});

名为 currentDiv 的 cookie 有一个从 1 到 8 的数字,当值高于 8 时,每次重新加载和重置时都会更改

如何显示带有当前值的 cookie(称为 currentDiv)?喜欢:

The installed cookies are:
currentDiv with the value (for example 5)

最佳答案

您可以这样做以列出所有页面 cookie:

<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.net/5p34S/

关于javascript - 如何在 .html 文件中显示 cookie 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23315854/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com