嗨,我正在尝试在我的网站上创建一个评论部分,我编写的代码将我输入的评论放在已经输入的评论下方。
我真正想做的是将新输入的评论放在旧评论之上(如 facebook 或 youtube 或任何其他网站 - 当您输入评论时,它会出现在旧评论上方(在第一行))我通过使用 javascript 来做到这一点?谢谢你。下面是我写的代码。
<input id = "txtboxComment" type = "text" onkeyup = "typeComment(event)" placeholder = "Write a comment"/>
<div id = "comment"></div>
#txtboxComment {
float: left;
width: 600px;
height: 25px;
margin-left: 10px;
margin-top: 10px;}
#comment {
border: solid 1px;
float: left;
width: 602px;
height: auto;
margin-left: 51px;
margin-top: 10px;
}
function typeComment(e) {
co = document.getElementById("txtboxComment");
if (e.keyCode == 13) {
co.click();
document.getElementById("comment").innerHTML += "<pre>" + co.value + "\n" + "</pre>";
}