如果一个 HTML 表单有两个 <input type="submit">按钮,我怎么知道哪个被点击了? [英] If an HTML form has two <input type="submit"> buttons, how do I know which got clicked?

查看:41
本文介绍了如果一个 HTML 表单有两个 <input type="submit">按钮,我怎么知道哪个被点击了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下 HTML 表单:

Suppose I have the following HTML form:

<form>
...
<input type="submit" name="queue" value="Queue item">
<input type="submit" name="submit" value="Submit item">
</form>

我如何知道用户点击了哪个按钮(不使用 JavaScript)?

How do I know which button the user clicked (without using javascript)?

我查看了提交的数据,似乎当点击 "Queue Item""queue" = "Queue Item" 被发送到服务器.当 "Submit item" 被点击然后 "submit" = "Submit item" 设置发送.

I looked at submitted data and it seems that when "Queue Item" is clicked then "queue" = "Queue Item" gets sent to the server. And when "Submit item" is clicked then "submit" = "Submit item" sets sent.

我可以依赖这种行为吗?它是否记录在 HTML 表单标准中的某处?你们是怎么做的?

Can I rely on this behavior? Is it documented somewhere in the standard on HTML forms? How do you guys do it?

推荐答案

是的,你可以依赖这个;它在这里有完整的文档记录.具体相关行说:

Yes, you can rely on this; it's fully documented here. The specific relevant lines say:

提交表单进行处理时,某些控件的名称与其当前值成对,并且这些对与表单一起提交.提交名称/值对的那些控件称为成功控件.

When a form is submitted for processing, some controls have their name paired with their current value and these pairs are submitted with the form. Those controls for which name/value pairs are submitted are called successful controls.

如果一个表单包含多个提交按钮,则只有激活的提交按钮成功.

If a form contains more than one submit button, only the activated submit button is successful.

这篇关于如果一个 HTML 表单有两个 &lt;input type="submit"&gt;按钮,我怎么知道哪个被点击了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆