我目前正在做一个学校项目,我负责从头开始创建论坛。我打算创建一个“添加部分”按钮,单击它时会创建一个新的问题框。不过,我不确定我该如何去做。如何永久存储用户数据
我到目前为止能够实现的目标是利用用户传递给我的数据,但是我无法确保一旦用户刷新后它仍然保留在我的代码中。这是本地存储的限制吗?如果是的话,我可以使用的任何替代方案?我的代码我的代码
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Testing.css">
<script>
function addNew(){
var datatwo = localStorage.datatwo;
var newData = document.createTextNode(datatwo);
var hello = document.createElement("th");
hello.appendChild(newData);
document.getElementById("Questions").appendChild(hello);
}
</script>
</head>
<body>
<div id="Addnew">
<button onclick="addNew()" id ="AddNewButton">Add new </button>
</div>
<h1>This is Page 1 </h1>
<table>
<tr id="Questions">
<th>What is my Name</th>
<th>What is his name</th>
</tr>
<tr>
<td>Justin</td>
<td>James</td>
</tr>
</table>
<nav>
<div id="footerPages">
<ul>
<li><p>Page 1 of 3</p></li>
<li><a href=""> < Prev </a></li>
<li><a href="#"> 1 </a></li>
<li><a href="Testing2.html"> 2 </a></li>
<li><a href="#"> 3 </a></li>
<li><a href="#"> 4 </a></li>
<li><a href="#"> 5 </a></li>
<li><a href="#"> 6 </a></li>
<li><a href="#"> 7 </a></li>
<li><a href="Testing2.html"> Next ></a></li>
</ul>
</div>
</nav>
</body>
</html>
第2页
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Testing.css">
<script>
function addNew(){
var data = prompt("What is your question?");
localStorage.datatwo = data;
}
</script>
</head>
<body>
<div id="Addnew">
<button onclick="addNew()" id ="AddNewButton">Add new </button>
</div>
<h1>HI THIS IS PAGE 2</h1>
<table>
<tr id="Questions">
<th>What is my Name</th>
<th>What is his name</th>
</tr>
<tr>
<td>Justin</td>
<td>James</td>
</tr>
</table>
<nav>
<div id="footerPages">
<ul>
<li><p>Page 1 of 3</p></li>
<li><a href="Testing.html"> < Prev </a></li>
<li><a href="Testing.html"> 1 </a></li>
<li><a href="#"> 2 </a></li>
<li><a href="#"> 3 </a></li>
<li><a href="#"> Next ></a></li>
</ul>
</div>
</nav>
</body>
</html>
看起来你的两页代码是一样的 –
你也可以采用(选择)任何现成的使用论坛,如cms为您的项目。 (PHP BB) –