我有这样的表格:
<form action = "" method = "get">
<input type = "input" name = "id" value = "3" />
<input type = "input" name = "name" value = "gloris" />
<input type = "submit" class = "button_big" name = "submit" value = "SEND" />
</form>
如何制作此链接(我必须使用按钮): www.link.com/3/gloris
答案 0 :(得分:2)
正如菲利克斯所说,这需要JavaScript。它会是这样的:
<script type="text/javascript">
window.addEventListener("load", function()
{
document.getElementById("myForm").addEventListener("submit", function()
{
var id = document.getElementById("id").value;
var name = document.getElementById("name").value;
window.location = [window.location.replace(/\/$/, ''), id, name].join("/");
}, false);
}, false);
</script>
<form action = "" id = "myForm" method = "get">
<input type = "text" name = "id" id = "id" value = "3" />
<input type = "text" name = "name" id = "name" value = "gloris" />
<input type = "submit" class = "button_big" name = "submit" id = "submit" value = "SEND" />
</form>
请注意,我添加了id
个属性,因此我们可以使用document.getElementById
。此外,没有输入类型“输入”。它应该是text
,或者您可以将其关闭。您可以添加更多字段,只需按所需顺序添加到数组中。
答案 1 :(得分:1)
<form action="http://www.link.com/3/gloris" method="get">
<input type="submit" value="Go to gloris" />
</form>
答案 2 :(得分:0)
我假设您的意思是如何在表单发布到的页面中建立链接?取决于您使用的技术。使用php它可能是
<a href="www.link.com/<?=$_GET['id']?>/<?=$_GET['name']?>">Your link name</a>
答案 3 :(得分:0)
如果PHP是您的选项,请使用表单操作链接代码,例如:
<?php
if (isset($_GET['id']) && isset($_GET['name'])) {
header('Location: www.link.com/' . $_GET['id'] . '/' . $_GET['name']);
}
?>
答案 4 :(得分:0)
首先,我会更新您的字段名称。命名项目“名称”绝不是一个好主意。另外,在表单中添加一个id。
<form action = "javscript:void();" method = "get" id = "mainForm">
<input type = "input" name = "itemId" value = "3" />
<input type = "input" name = "itemName" value = "gloris" />
<input type = "submit" class = "button_big" name = "submit" value = "SEND" />
</form>
<button onclick="updateLocation();">Submit</button>
然后只需制作一个javascript函数。
<script><!--
function updateLocation(){
var formObject=document.getElementById('formObject');
var i = formObject.itemId.value;
var n = formObject.itemName.value;
var url = 'www.link.com/' + i + '/' + n;
window.location=url;
}
--></script>