【问题标题】:how to left text search in input after submit提交后如何在输入中留下文本搜索
【发布时间】:2019-11-22 12:51:55
【问题描述】:

我有搜索输入。当我写一个数字来查找某些东西(这是一个 HTTP 请求)时,我得到了一些结果,但是我输入的数字消失了。我怎样才能离开它?

     div class="control is-expanded">
          <input
            name="request_id"
            class="input"
            placeholder="Request ID"
          />
        </div>
        <div class="control">
          <input type="submit" name="submit" class="button is-link" />
        </div>

在 beckent 上的 HTTP 请求,我没有写。我只做前端。我可以改变这个吗?

【问题讨论】:

  • 在会话中存储输入值或获取后值并再次以表单返回并在 value="".

标签: html input submit


【解决方案1】:

HTML:

<form method="post" action="" onSubmit="return saveComment();">
    <input type="text" name="request_id" class="input" placeholder="Request ID from Furia" />
    <input type="submit" name="submit" class="button is-link" />
</form>

JavaScript:

document.getElementById("request_id").value = localStorage.getItem("comment");

function saveComment() {
    var comment = document.getElementById("request_id").value;
    if (comment == "") {
        alert("Please enter a comment in first!");
        return false;
    }

    localStorage.setItem("comment", comment);
    alert("Your comment has been saved!");

    location.reload();
    return false;
}

【讨论】:

    猜你喜欢
    • 2011-01-18
    • 1970-01-01
    • 2016-05-20
    • 2020-06-08
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    相关资源
    最近更新 更多