我有这样一个表格:
<form action="http://localhost/test">
<input type="text" name="keywords">
<input type="submit" value="Search">
</form>
如果我键入一个值,假设在文本输入字段中输入“hello”并提交表单,则 URL 如下所示:http://localhost/test/?keywords=hello
。
我希望将值附加到操作路径。所以基本上,在提交表单后,URL 应该如下所示:
http://localhost/test/hello
最佳答案
您可以使用 onsubmit
属性并在函数内设置操作,例如:
<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 ;
}
关于javascript - 将表单输入值附加到操作 url 作为路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34128361/