在不使用图像或 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/