提交&#34;表格&#34;使用<form>标签外的按钮

时间:2018-01-24 18:24:51

标签: html5

如何使用表单外的提交按钮提交该表单?
我用过这个解决方案。 https://stackoverflow.com/a/23456905/9263599 但我有三种形式,上面的解决方案仅用于1种形式,我不想使用JS。

     <form method="get" action="something.php">
         <input type="text" name="name" />
         <input type="submit" id="submit-form" class="hidden" />
    </form>

     <form method="get" action="something.php">
         <input type="text" name="name" />
         <input type="submit" id="submit-form1" class="hidden" />
    </form>

     <form method="get" action="something.php">
         <input type="text" name="name" />
         <input type="submit" id="submit-form2" class="hidden" />
    </form>

     <button type="submit" name="publish" class="btn btn-sm btn-info">
         <label for="submit-form" tabindex="0">Submit</label>
         <label for="submit-form1" tabindex="0"></label>
         <label for="submit-form2" tabindex="0"></label>
     </button>

行。谢谢你的回答!

1 个答案:

答案 0 :(得分:2)

试试这个:

 <form method="get" id="form1" action="something.php">
     <input type="text" name="name" />

</form>

 <form method="get" id="form2" action="something.php">
     <input type="text" name="name" />

</form>

 <form method="get" id="form3" action="something.php">
     <input type="text" name="name" />

</form>

<button type="submit" form="form1">Form1 Submit</button>
<button type="submit" form="form2">Form2 Submit</button>
<button type="submit" form="form3">Form3 Submit</button>

<form method="get" id="form1" action="something.php">