HTML:如何确保按下回车键时触发正确的提交输入?
我有一张包含三个提交输入的表单(优惠券代码、兑换礼品卡、表单提交)。输入按照我刚才提到的顺序放置在页面上,因此当用户按下 Enter 时,始终会提交优惠券代码。有没有办法在按下回车键时只触发表单提交?如果可能的话,我希望在没有任何客户端编码的情况下完成此任务。
<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 提交,因为这定义了另一个字段并且不由 PHP 表单验证脚本处理。 是我尝试使用的,但是当按下回车键时,应用按钮仍然被触发。
I have one form with three submit inputs (coupon code, redeem gift card,form submit). The inputs are placed on the page in the order I just mentioned so when the user presses enter the coupon code is always being submitted. Is the there a way to have only the form submit triggered when the enter key is pressed? I would like to accomplish this without any client-side coding if possible.
<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>
What I am trying to do is have the submit inputs in section 2 and 3 not get triggered when the enter key is pressed. I want the submit input in section 4 to be the one triggered when the enter key is pressed. I would rather not change the Apply submits to an since this defines another field and is not handled by the PHP form validation script. <button></button>
is what I have tried using but when the enter key is pressed the Apply buttons are still being triggered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能有些代码可以提供帮助,但一个简单的方法是在
type="submit"
中设置“表单提交”,并在type="中设置另外两个优惠券代码和兑换礼品卡按钮”
。May be some code can help but a easy way to do it is set your "form submit" in
type="submit"
and your two other coupon code and redeem gift card intype="button"
.