【问题标题】:use a tag to submit form to other page使用标签将表单提交到其他页面
【发布时间】:2013-10-26 07:11:39
【问题描述】:

我想使用 a 标签将表单提交到另一个页面。但是,当我这样做并使用 href="" 转到此页面时,似乎没有提交表单。它看起来像这样:

<form id="SomeForm" action="SomePage.php" method="GET">
    <!--Here are some inputs-->
</form>

<a href="SomePage.php" onclick="javascript:document.getElementById('SomeForm').submit();">
    The link to click on
</a>

点击此链接时,浏览器转到正确的页面,但提交的表单不见了。我使用 javascript 代码行为页面创建了一个大 URL,因此它看起来像是已提交,但我也希望能够使用 method="POST" 提交表单。如果它在同一页面上并且 href="#" 有效,否则无效。有没有办法做到这一点?

【问题讨论】:

标签: javascript html forms input hyperlink


【解决方案1】:
<a href="#" onclick="javascript:document.getElementById('SomeForm').submit();">
    The link to click on
</a>

替代方案:

<div id="someID" onclick="javascript:document.getElementById('SomeForm').submit();">
    <!-- Click anywhere in this div to submit the form -->
</div>

【讨论】:

  • 我使用了链接标签,所以光标会变成指针手,但我刚刚找到了在没有链接标签的情况下使用它的方法,以及您提供的替代方法。它是双向的。
  • 很高兴能帮上忙! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
  • 2014-04-09
  • 1970-01-01
  • 1970-01-01
  • 2014-06-20
相关资源
最近更新 更多