<form action="/foo">
        <input type="text" name="q">
        <input type="submit" >
</form>

In the previous HTML, if the user types in 'bar' and clicks the button it would submit to example.com/foo?q=bar. How can I make it go to example.com/foo/bar? I can easily do it with JS but I'm trying to stick to HTML.

有帮助吗?

解决方案

There is no way to do this in HTML, you need a programming language.

Have something on the server process the form an issue an HTTP 301 response with a Location header.

You could enhance that by use the form's submit event to prevent the default action and set location in JS.

其他提示

You cannot change the value of the action attribute with HTML only. You need to use JS or any other scripting language.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top