将表单输入值作为路径附加到操作 url [英] Appending form input value to action url as path
本文介绍了将表单输入值作为路径附加到操作 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的表格:
<form action="http://localhost/test">
<input type="text" name="keywords">
<input type="submit" value="Search">
</form>
如果我输入一个值,假设在文本输入字段中输入hello"并提交表单,则 URL 如下所示:http://localhost/test/?keywords=hello
.
If I type a value, let's say: 'hello' in the text input field and submit the form, the URL looks like: http://localhost/test/?keywords=hello
.
我希望将值附加到操作路径.所以基本上,在表单提交之后,URL 应该是这样的:
I want the value to get appended to the action path. So basically, after the form submission the URL should look like:
http://localhost/test/hello
推荐答案
您可以使用 onsubmit
属性并在函数内设置动作,例如:
You can use onsubmit
attribute and set the action inside a function for example:
<form id="your_form" onsubmit="yourFunction()">
<input type="text" name="keywords">
<input type="submit" value="Search">
</form>
function yourFunction(){
var action_src = "http://localhost/test/" + document.getElementsByName("keywords")[0].value;
var your_form = document.getElementById('your_form');
your_form.action = action_src ;
}
这篇关于将表单输入值作为路径附加到操作 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文