如何将当前页面数据保存为html、css、javascript?

问题描述 投票:0回答:2

刷新浏览器时,我试图保存用户创建的按钮。这意味着我希望它永久保留在那里。

以下是我们正在讨论的内容的片段:

function create(){
  const a =  document.createElement("button")
  document.body.appendChild(a)
   const b = document.getElementById("buttoname")
   a.innerHTML = b.value
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>Create a button</h1>
Button name:<input id="buttoname" type="text"><br>

<button onclick="create()">Create Button</button>

</body>

   
</html>
感谢您的帮助,这意味着很多。

javascript html
2个回答
0
投票

查看

localStorage
- docs,您可以在那里保存一个变量,其中包含每个创建的按钮的信息。然后,您需要一个函数,该函数将在页面加载时读取
localStorage
并创建所描述的按钮


0
投票

如果您愿意仅在当前工作的设备上保存数据,那么您可以使用浏览器的本地存储。但是,如果您在网上某个地方有一个网页,并且希望能够从世界上任何地方的任何设备调用保存的数据,那么您必须使用一些后端存储系统。对于我的小项目,我使用名为 Little Data API 的 Web API 服务,但我确信还有很多其他服务...

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