如何在上次发布的评论上方显示网站评论

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

嗨在我的网站上我有一个评论框,每次我发表评论它都会发布在最后评论下面我的问题是:我如何在旧评论之上添加新评论。

网站:kru.run

这是我现在的完整代码,

<textarea id="title1" type="text " rows="1" cols="15" onkeyup="Allow()" placeholder="username"></textarea>
<textarea id="title" type="text " rows="3" cols="125" onkeyup="Allow()" placeholder="write a comment..."></textarea>
<input type="submit" value="Send" onclick="insert()" style="width:50px;" /></form>
</div>
<div id="display"></div>
<script type="text/javascript">
    var titles = [];
    var titleInput = document.getElementById("title");
    var titleInput1 = document.getElementById("title1");
    var messageBox = document.getElementById("display");

    function Allow() {
        if (!user.title.value.match(/[a-zA-Z]$/) && user.title.value != "") {
            user.title.value = "";
            alert("Please Enter only alphabets");
        }
        window.location.reload()
    }

    function insert() {
        titles.push(titleInput1.value + ": " + titleInput.value);
        clearAndShow();
    }

    function clearAndShow() {
        titleInput.value = "";
        messageBox.innerHTML = "";
        messageBox.innerHTML += " " + titles.join("<br/> ") + "<br/>";
    }
</script>
</div>
</div>
</div>
<br><br>

特别是我认为插入功能是什么我可以使用而不是推?

function insert () {
    titles.push(titleInput1.value + ": " + titleInput.value);
    clearAndShow();
}
html
1个回答
1
投票

尝试:

function insert () {
titles.unshift(titleInput1.value + ": " + titleInput.value);
clearAndShow();
}

作为第一项插入。

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