How to make a submit out of a link?

2019-01-22 10:39发布

I got an image with which links to another page using <a href="..."> <img ...> </a>.

How can I make it make a post like if it was a button <input type="submit"...>?

10条回答
相关推荐>>
2楼-- · 2019-01-22 11:06

It looks like you're trying to use an image to submit a form... in that case use <input type="image" src="...">

If you really want to use an anchor then you have to use javascript:

<a href="#" onclick="document.forms['myFormName'].submit(); return false;">...</a>

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-22 11:07

Dont forget the "BUTTON" element wich can handle some more HTML inside...

查看更多
Animai°情兽
4楼-- · 2019-01-22 11:10
 <html>

 <?php

 echo $_POST['c']." | ".$_POST['d']." | ".$_POST['e'];

 ?>

 <form action="test.php" method="POST">
      <input type="hidden" name="c" value="toto98">
      <input type="hidden" name="d" value="toto97">
      <input type="hidden" name="e" value="toto aaaaaaaaaaaaaaaaaaaa">

      <a href="" onclick="document.forms[0].submit();return false;">Click</a> 
 </form>

</html>


So easy.




So easy.
查看更多
\"骚年 ilove
5楼-- · 2019-01-22 11:12

More generic approatch using JQuery library closest() and submit() buttons. Here you do not have to specify whitch form you want to submit, submits the form it is in.

<a href="#" onclick="$(this).closest('form').submit()">Submit Link</a>
查看更多
小情绪 Triste *
6楼-- · 2019-01-22 11:20

Untested / could be better:

<form action="page-you're-submitting-to.html" method="POST">
    <a href="#" onclick="document.forms[0].submit();return false;"><img src="whatever.jpg" /></a>
</form>
查看更多
祖国的老花朵
7楼-- · 2019-01-22 11:22

input type=image will do it for you.

查看更多
登录 后发表回答