如何使用javascript将数据保存到cookie中?

时间:2021-09-14 07:28:49

so I wanted to create a HTML/Javascript project which could save little bits of data even after it was closed. I had considered web hosting it on a server, but I didn't think it was worth it.

所以我想创建一个HTML / Javascript项目,即使在关闭后也可以节省一些数据。我曾考虑过在服务器上托管它,但我认为这不值得。

<script>
    var a = 1
</script>

So, if I had a variable a which equals 1, how would I save that data into cookies so that when I reopen the project, it turns back to 1 instead of resetting to 0 assuming that there is code that resets it? Thanks for your time and effort!

所以,如果我有一个等于1的变量a,我如何将这些数据保存到cookie中,这样当我重新打开项目时,它会变回1而不是重置为0,假设有代码重置它?感谢您的时间和精力!

1 个解决方案

#1


Resolved now. I found out the document.cookie thing.

现在解决了。我发现了document.cookie的东西。

#1


Resolved now. I found out the document.cookie thing.

现在解决了。我发现了document.cookie的东西。