微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HTML表单中的多个提交按钮

如何解决HTML表单中的多个提交按钮

我希望这有帮助。我只是在float按右边的按钮。

这样,Prev按钮位于按钮的左侧Next,但Next在HTML结构中排在第一位:

.f {

  float: right;

}

.clr {

  clear: both;

}


<form action="action" method="get">

  <input type="text" name="abc">

  <div id="buttons">

    <input type="submit" class="f" name="next" value="Next">

    <input type="submit" class="f" name="prev" value="Prev">

    <div class="clr"></div><!-- This div prevents later elements from floating with the buttons. Keeps them 'inside' div#buttons -->

  </div>

</form>

优于其他建议的好处:没有JavaScript代码,无法访问,并且两个按钮都保留type="submit"

解决方法

假设您以HTML表单创建向导。一键向后退,一键向前。当您按下时,由于 后退 按钮首先出现在标记中Enter,它将使用该按钮提交表单。

例:

<form>

  <!-- Put your cursor in this field and press Enter -->

  <input type="text" name="field1" />



  <!-- This is the button that will submit -->

  <input type="submit" name="prev" value="Previous Page" />



  <!-- But this is the button that I WANT to submit -->

  <input type="submit" name="next" value="Next Page" />

</form>

我想确定当用户按下时使用哪个按钮提交表单Enter。这样,当您按下Enter向导时,向导将移至下一页,而不是上一页。您是否必须使用tabindex此功能?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。