繁体   English   中英

根据用户输入重定向到 html 页面

[英]Redirect to html page based on user input

我在用户输入城市位置的网页上有一个文本框。 我希望将其合并到 url 中。 我有一个 Spring controller 可以处理这些网址,但我首先无法重定向到该 url。 这是我的代码

<span id = "form">
            <form  id = "input" target="_self" action="http://localhost:8090/location/city" method="GET" th:action="@{/location/city}">
                <label for="loc" align = right>Location:</label>
                <input type="text" placeholder="Enter Location" th:name= "location" id="loc">
                <input type="submit" value="Submit" onclick="setMode()">
            </form>
            <script>
                document.getElementById("input").action = "http://localhost:8090/location/" + document.getElementById("loc").value;
            </script>

我只想添加城市名称,但是当用户单击提交时,url 变为“/?location=cityname”我想要“/location/cityname.

<input type="submit" value="Submit" onclick="setMode()">

type="submit" 将触发提交 forms 的基本浏览器标准。 当您将其更改为没有 href 的锚链接时,它将起作用。 您当然可以设置锚链接的样式,使其看起来像一个按钮。 否则你应该使用 event.preventDefault(); 防止表单提交。

您可以使用;

<a onclick='setMode()' >Submit</a>

代替;

<input type="submit" value="Submit" onclick="setMode()">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM