【问题标题】:How to retain input values, after redirected in html?在html中重定向后如何保留输入值?
【发布时间】:2017-06-18 10:26:29
【问题描述】:

我正在使用 thymeleaf、html、angularjs、js 和 spring boot 来创建 Web 应用程序。我的主要问题是如何保留输入值并将该值显示在下一页的输入框中?

示例:当您在右上角的搜索栏中键入问题时,堆栈溢出,您会被重定向,并且您还会获得一个新的搜索栏,该搜索栏的值与您之前输入的相同。

Index.html

<form action="getDetails" method="POST">

    <p> Mac Address: </p><input type="text" name="inputMacAddress" id="inputMacAddress" required="required" placeholder="Enter Mac Address"  />

    <br/>

    <input type="submit" value="Submit" class="marginButton"/> <input type="reset" value="Clear" onclick="Redirect();" class="marginButton" />
    <script>
        function Redirect() {
            window.location.href = 'http://www.localhost:8080';
        }
    </script>

</form>

getDetails.html

<form action="getDetails" method="POST">

    <p> Mac Address: </p><input type="text" name="inputMacAddress" id="inputMacAddress" required="required" placeholder="Enter Mac Address"  />

    <br/>

    <input type="submit" value="Submit"/> <input type="reset" value="Clear" onclick="Redirect();" />
    <script>
        function Redirect() {
            window.location.href = 'http://www.localhost:8080';
        }
    </script>

</form>

【问题讨论】:

  • 你不懂PHP还是不想用?
  • 查看 URL 查询参数
  • @AymDev 不想使用 PHP。
  • URL 查询、cookie、localstorage,让后端在 POST 之后返回它,使用角度路由......这么多选项。此外,SO 可能不会重新加载标题,因此标题实际上并没有改变。

标签: javascript html angularjs thymeleaf


【解决方案1】:

您需要使用 GET 或 POST 传递参数。在大多数情况下,使用 GET。 例如http://localhost.html?q="Hello+world"

然后将该 GET 值传递给输入。

看看$routeParamshere

【讨论】:

    【解决方案2】:

    你在你的应用程序中使用 Angular 路由吗?在您的重定向中(假设您从您的角度代码重定向),您可以将查询参数添加到您的 URL 并使用 $routeParams 在您的第二页上获取它们。

    【讨论】:

    • 你能给我一个关于 routeParams 的简单例子吗?
    猜你喜欢
    • 2018-08-22
    • 1970-01-01
    • 2010-12-20
    • 2011-01-18
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多