从其他形式定位按钮

时间:2016-05-13 11:46:01

标签: html forms

这个可以用JavaScript制作,但我对纯HTML解决方案很好奇。我对这个问题的看法是什么:

我有一张表格:

<form action...>
    <input type... />
    <label for...>...</label>
    and other elements for basic form...

    <button type="submit">Send</button>
    <button type="submit" target="hidden-form">Remove</button>
</form>

在其他地方,我有另一种形式:

<form id="hidden-form" action...>
    <input type="hidden"... />
</form>

所以我的观点是,按下“删除”按钮将发布表单#hidden-form。有可能吗?我尝试了该属性target,但没有帮助。

2 个答案:

答案 0 :(得分:1)

您可以使用<button>'s form attribute

<button type="submit" form="hidden-form">Remove</button>

<form id="hidden-form" action...>

答案 1 :(得分:0)

我认为你想要这样的东西,使用jQuery可以尝试:

&#13;
&#13;
$("#remove").click(function(){
	$('#hidden-form').submit();
});
&#13;
<form action...>
    <input type... />
    <label for...>...</label>
    and other elements for basic form...

    <button type="submit">Send</button>
    <button type="submit" id="remove" onClick="document.forms['hidden-form'].submit();
">Remove</button>
</form>


<form id="hidden-form" action...>
    <input type="hidden"... />
</form>
&#13;
&#13;
&#13;

相关问题