html - 使用标签提交表单

标签 html click onclick label labels

在不使用图像或 javascript 的情况下很难设置提交输入的样式。

据我所知,无法将 HTML 代码直接插入 sumbit 输入值中。如果我将提交输入包装在一个 div 元素中(例如添加多个边框),则不是整个区域都可以点击。

单击标签是否会导致提交表单 在所有浏览器中 ?

<form method="test.rb">
 <input type="text" name="test" id="test" />
 <label for="button">
  <input type="submit" name="button" id="button" value="Send!" />
 </label>
</form>

最佳答案

根据 the W3C on associating labels :

The label element is not used for the following because labels for these elements are provided via the value attribute (for Submit and Reset buttons), the alt attribute (for image buttons), or element content itself (button).



感谢 @Jeremiah Isaacson指出这一点。

旧答案

是的,这会奏效。我无法验证所有浏览器的行为,但这里是 W3C spec has to say :

To associate a label with another control implicitly, the control element must be within the contents of the LABEL element ... When a LABEL element receives focus, it passes the focus on to its associated control.



因此,我想通过单击 LABEL,您实际上是在单击提交输入。

感谢@stevelove 指出这样做的可行性。

关于html - 使用标签提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4257474/

相关文章:

python - 如何显示包含本地 Python 函数可点击链接的 Pandas 单元格?

python - 单击按钮后打开新窗口

onclick - 将子事件暴露给父事件

java - 修复 Java 中的序列化 HTML

html - 我怎样才能用CSS制作对 Angular 线

PHP截断时出现 fatal error

jquery - 防止一个 jQuery 事件与另一个事件发生

html - 编辑 Shopify 的结帐

jquery - 使用 PNG 的 Alpha 作为 "hotspot"来附加单击/悬停事件,可能吗?

javascript - 设置一个数组来选择不同的变量onclick