【问题标题】:HTML: How would I ensure the correct submit input was triggered when pressing the enter key?HTML:我如何确保在按下回车键时触发了正确的提交输入?
【发布时间】:2011-07-21 06:36:54
【问题描述】:

我有一个包含三个提交输入的表单(优惠券代码、兑换礼品卡、表单提交)。输入按我刚才提到的顺序放置在页面上,因此当用户按下输入时,优惠券代码总是被提交。有没有办法在按下回车键时只触发表单提交?如果可能的话,我想在没有任何客户端编码的情况下完成这个。

<form>
    <!-- start section 1 -->
    <input type="text" name="input1" id="input1" /><br />
    <input type="text" name="input2" id="input2" /><br />
    <!-- end section 1 -->

    <!-- start section 2 -->
    <input type="text" name="couponCodes" id="couponCodes" /><br />
    <input type="submit" name="orderBy" id="orderBy" valeue="Apply" /><br />
    <!-- end section 2 -->

    <!-- start section 3 -->
    <input type="text" name="giftCards" id="giftCards" /><br />
    <input type="submit" name="orderBy" id="orderBy" valeue="Apply" /><br />
    <!-- end section 3 -->

    <!-- start section 4 -->
    <input type="text" name="input3" id="input3" /><br />
    <input type="submit" name="orderBy" id="orderBy" valeue="Place Order" />
    <!-- end section 4 -->
</form>

我想要做的是在按下回车键时不会触发第 2 节和第 3 节中的提交输入。我希望第 4 节中的提交输入是按下回车键时触发的输入。我宁愿不将 Apply 提交更改为 an,因为它定义了另一个字段并且不由 PHP 表单验证脚本处理。 &lt;button&gt;&lt;/button&gt; 是我尝试使用的,但是当按下回车键时,应用按钮仍然被触发。

【问题讨论】:

  • 你到底想达到什么目的?请问代码?
  • 只有一种形式,还是多种形式?
  • 这是一种由四个部分和三个提交输入组成的表单。
  • 没有一个确切的例子很难给出一个好的解决方案。

标签: html forms form-submit


【解决方案1】:

可能有一些代码可以提供帮助,但一个简单的方法是在type="submit" 中设置您的“表单提交”,在type="button" 中设置您的另外两个优惠券代码和兑换礼品卡。

【讨论】:

    猜你喜欢
    • 2012-01-02
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多