gpt4 book ai didi

javascript - 使用 javascript 将文本框保存为 cookies 并打印结果

转载 作者:行者123 更新时间:2023-12-02 20:05:22 24 4
gpt4 key购买 nike

我是 JavaScript 新手,我需要一个简单的解决方案。

如何从第一个 html 页面保存两个文本框,并将其显示在另一个 html 页面中。

最佳答案

使用本地存储:http://jsfiddle.net/usNwP/localStorage 是一个对象,其值在同一域的页面之间持续存在(在重新加载、导航甚至重新启动计算机后也是如此)。

document.getElementById('save').onclick = function() {
// save values into localStorage
localStorage['input1'] = document.getElementById('input1').value;
localStorage['input2'] = document.getElementById('input2').value;
};

// load textboxes from localStorage (can be on another page)
document.getElementById('input1').value = localStorage['input1'] || "";
document.getElementById('input2').value = localStorage['input2'] || "";

关于javascript - 使用 javascript 将文本框保存为 cookies 并打印结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7499022/

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