使用href提交表单

时间:2014-01-04 15:28:23

标签: javascript php html forms

我有一张表格

<form method="post" id="ff">

<input type="name" id="aa" />

<input type="name" id="bb" />

<a href="http://www.example.php "> Submit </a>

</form>

是否可以使用href发布?我需要将数据发布到href url.Is有可能吗? 有人可以帮忙吗?

我不想使用普通的action=

5 个答案:

答案 0 :(得分:6)

你可以试试这个

<form method="post" action="http://www.example.php" id="ff">
<input type="name" id="aa" />
<input type="name" id="bb" />
<a href="javascript: submitForm();"> Submit </a>

</form>
<script>
function submitForm(){
    $('#ff').submit();
}
</script>

答案 1 :(得分:4)

为什么不使用

<form method="post" id="ff" action="http://www.example.php">

...

</form>

答案 2 :(得分:3)

是的,你可以这样做,但它需要JavaScript:

<a href="javascript:document.getElementById('ff').submit();"> Submit </a>

您还可以编写更复杂的JavaScript函数并调用它。

答案 3 :(得分:0)

将目标网址指定为action的<{1}}属性:

form

严格地说,你问的是可能但不漂亮:

<form method="post" action="http://www.example.php">

我会选择<a href="http://www.example.php" onclick="var e=document.getElementById('ff').action=this.href;e.submit();return false">Submit</a> 而不是......

答案 4 :(得分:0)

relace:

<a href="http://www.example.php "> Submit </a>

使用:

<a href="http://www.example.php" onclick="frmsubmit(this);"> Submit </a>
<script type="text/javascript">
function frmsubmit(obj){
  var url = obj.href;
  document.getElementById('ff').action = url;
  document.getElementById('ff').submit();
}
</script>

如果你有多个标签而不是使用id并找到它而不是标签名称