gpt4 book ai didi

html - 如果不发布,为什么人们将值 ="Submit"用于表单中的按钮元素

转载 作者:太空宇宙 更新时间:2023-11-04 13:07:00 24 4
gpt4 key购买 nike

我见过有人这样做:

<form ..>

<button type='submit' value='Submit'>Sign Up</button>
</form>

为什么他们需要 value='Submit' 如果它甚至没有提交到服务器?它是为了辅助功能吗?

最佳答案

表单可以有多个提交按钮。如果您还为每个按钮指定了一个名称,那么您可以在提交后使用该值来查看点击了哪个按钮。

<!DOCTYPE html>
<html>
<head>
<title>test submit</title>
</head>
<body>
<form action="#" method="get">
<button type='submit' name="clicked" value="thefirst">First</button>
<button type='submit' name="clicked" value="thesecond">Second</button>
</form>
</body>
</html>

如果您使用第一个按钮提交,则发布的参数将为 clicked=thefirst,而对于第二个按钮,则为 clicked=thesecond

当然,在这种情况下,更明智的方法是给按钮不同的名称。但你明白了。

关于html - 如果不发布,为什么人们将值 ="Submit"用于表单中的按钮元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39673255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com