Html 使用 <a> 锚元素提交表单,不使用 javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17078151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Submit a form using <a> anchor element, without javascript
提问by Souad
How to replace the submit button with a link without using javascript ? is there any way to add the submit attribute to a link ? because the form will not be sent by a simple link without "submit".
如何在不使用 javascript 的情况下用链接替换提交按钮?有没有办法将提交属性添加到链接?因为表格不会通过没有“提交”的简单链接发送。
<form:form action="/getPage" >
<div class="buttons">
<a class="link" href="">
<img src="icon.png" />
</a>
</div>
</form:form>
I work in an application web so if i use javascript the link will not be mapped by the server ..
我在一个应用程序网络中工作,所以如果我使用 javascript,服务器将不会映射链接..
回答by d-_-b
You can not submit a form using an <a>
tag alone. You willneed some type of javascript to assist, if you insist on using the <a>
tag:
您不能<a>
单独使用标签提交表单。如果您坚持使用标签,您将需要某种类型的 javascript 来协助<a>
:
<a href="#" onclick="$(this).closest('form').submit()">Submit the Form</a>
<a href="#" onclick="$(this).closest('form').submit()">Submit the Form</a>
or
或者
<a href="#" onclick="document.getElementById('form-id').submit()">Submit the Form</a>
<a href="#" onclick="document.getElementById('form-id').submit()">Submit the Form</a>
or super hack:
或超级黑客:
<a href="backendPage.php?param1=yes¶m2=no">Submit the Form</a>
, then on backendPage.php you can use $_GET
requests to process information, and redirect the visitor to the intended page. But that's a horrible idea haha
<a href="backendPage.php?param1=yes¶m2=no">Submit the Form</a>
,然后在 backendPage.php 上,您可以使用$_GET
请求来处理信息,并将访问者重定向到预期页面。但这是一个可怕的想法哈哈
回答by by0
Try this:
尝试这个:
CSS
CSS
button {
background:none!important;
border:none;
padding:0!important;
/*border is optional*/
border-bottom:1px solid #444;
}
HTML
HTML
<button>your button that looks like a link</button>
回答by Angelina
This can achieve the same effort and it looks like <a>
这可以实现相同的努力,看起来像 <a>
Note:btn
btn-link
comes from bootstrap
注:btn
btn-link
来自bootstrap
<button class="btn btn-link" type="submit"><img src="icon.png" /></button>
回答by Manpreet Singh Dhillon
There is an another way out. Using this method you can use any element to submit a form. Following is an example:
还有另一种出路。使用此方法,您可以使用任何元素来提交表单。下面是一个例子:
<span onclick="$('#submit').trigger('click')" style="cursor:pointer;">
anything
</span>
Add a hidden submit button:
添加一个隐藏的提交按钮:
<input style="display:none;" type="submit" id="submit"/>
This will behave exactly as actual submit button.
这将与实际的提交按钮完全一样。