如何使用JavaScript生成Cookie?

问题描述 投票:-2回答:1

所以标题:票证:24f17b238e0b6c40b4f0991aa0d78b7d2daded3f8716c9b696d04662047d1502e66653fbdf4ac17f2c3f14100976df4dfaa62314bdefc105f5be0a897151c2e41587137268

_ ticket:83b54a72410413710a5622d3cd4216f90de7eec029570a85993a946c04805c1cf1060604ff32334cb4f7ead1b0f4bfda849e005b2b74510c260da0c9b4760a371587137395]

因此需要有一个脚本来生成这些头。

所以标头:票证:24f17b238e0b6c40b4f0991aa0d78b7d2daded3f8716c9b696d04662047d1502e66653fbdf4ac17f2c3f14100976df4dfaa62314bdefc105f5be0a897151c2e41587137268 _> [

您可以使用document.cookie,但我不建议您使用。最简单的方法是:

// setting localStorage.setItem("key", "value"); // key and value are always strings! // getting localStorage.getItem("key"); // returns always a string! // so: localStorage.setItem("_ticket", "83b54a72410413710a5622d3cd4216f90de7eec029570a85993a946c04805c1cf1060604ff32334cb4f7ead1b0f4bfda849e005b2b74510c260da0c9b4760a371587137395"); localStorage.setItem("_ticket", "83b54a72410413710a5622d3cd4216f90de7eec029570a85993a946c04805c1cf1060604ff32334cb4f7ead1b0f4bfda849e005b2b74510c260da0c9b4760a371587137395");

如果要存储对象或数组,则必须使用JSON.stringify和JSON.parse。
javascript json api cookies webassembly
1个回答
0
投票

// setting localStorage.setItem("key", "value"); // key and value are always strings! // getting localStorage.getItem("key"); // returns always a string! // so: localStorage.setItem("_ticket", "83b54a72410413710a5622d3cd4216f90de7eec029570a85993a946c04805c1cf1060604ff32334cb4f7ead1b0f4bfda849e005b2b74510c260da0c9b4760a371587137395"); localStorage.setItem("_ticket", "83b54a72410413710a5622d3cd4216f90de7eec029570a85993a946c04805c1cf1060604ff32334cb4f7ead1b0f4bfda849e005b2b74510c260da0c9b4760a371587137395");

© www.soinside.com 2019 - 2024. All rights reserved.