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

查看:122
本文介绍了如果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=队列项被发送到服务器。当>提交项目被点击,然后提交=提交项目发送集合。

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:


当一个表单被提交处理时,一些控件的名字与它们的当前值配对,这些对是随表格提交。那些提交了名称/值对的控件称为成功控件。


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

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

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

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