我试图做一个评论页面(纯javascript没有Jquery)并且已经到了我按下提交按钮但是当我刷新时我能够显示它的地方这一切都消失了。
此外,我还尝试制作一个下拉列表,帮助我过滤5分钟前/ 10分钟前输入的评论,但我不知道如何开始。一个完全可行的解决方案可能是最好的,因为我能够查看并理解代码,但实际上任何帮助都是值得赞赏的。谢谢
jsfiddle,如果这有助于https://jsfiddle.net/ybqk9rnb/
<html>
<head>
<link rel='stylesheet' type='text/css' href='CommentsPage.css'>
<script>
var arrayofcomments = []
var listofcomments = []
var i = 0
function action(){
var comment = document.getElementById('header').value;
arrayofcomments.push(comment);
localStorage.setItem('commentstorag',arrayofcomments);
document.getElementById('header').value = " ";
var username = 'username:'
var para = document.createElement('P');
para.innerHTML= username + arrayofcomments[i] + '<br>';
listofcomments.push(para);
document.getElementById('hello').appendChild(para);
var bio = document.getElementById('hello').querySelector('*');
i = i + 1
localstorage.setItem('commentstorage',bio);
}
function sol(){
var nano = document.getElementById('hello')
nano = localStorage.getItem('commentstorag')
}
</script>
</head>
<body>
<ul>
<li><a href='home'>Home</a></li>
<li class='dropdown'><a class='dropbtn'>News</a><div class='dropdown-
content'>
<a href='CommentsPage.html'>User Comments</a>
<a href='OfficialNews.html'>Official News</a>
</div>
</li>
<li class='dropdown'><a class='dropbtn'>Card</a><div class='dropdown-
content'>
<a href='topup'>Top Up</a>
<a href='balancecalc'>Balance Calculator</a>
</li>
</div>
<li class='dropdown'><a class='dropbtn'>Lost and Found</a><div
class='dropdown-content'>
<a href='reportyourmissingitem'>Report Your Missing Item</a>
<a href='reportfounditem'>Report Found Item</a>
</div>
</li>
<li><a href='feedback'>Feedback</a></li>
<li><a href='signup'>Sign Up</a></li>
</ul>
<h1 class='userupdates'> User Updates </h1>
<h2 class='para'> This is the User Updated page. Please use appropriate
language. Thank you!</h2>
<textarea id='header' type='text' rows='6' cols='100' name='server'>
</textarea>
<input onclick="action(); " type="button" value='Comment'>
<span onload='sol();' id='hello'>
</span>