为什么这个 XHTML 表单无法验证?
任何想法为什么这不会在这里验证:
http://validator.w3.org/#validate_by_input
表单输入标签似乎是错误的,但通读 XHTML 规范,它们应该可以正常验证。 有任何想法吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
</head>
<body>
<div class="Header">
<table class="HeaderTable">
<tr>
<td>
<div class="Heading">Test <span class="Standard">Test</span>
</div>
</td>
<td>
<div class="Controls">
<form id="ControlForm" method="get" action="Edit.php">
<input type="submit" name="action" id="Edit" value="Edit" />
<input type="submit" name="action" id="New" value="New" />
</form>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试在输入周围放置一个
fieldset
标记。 我认为 XHTML 中表单的想法是它们不能有不是 div、fieldset 等的直接后代。Try putting a
fieldset
tag around the inputs. I think the idea of forms in XHTML is that they can't have direct descendants that aren't div, fieldset, etc.您需要移动
它,使其位于
这很好地验证了
You need to move
so that it's inside the <form tag
This validates nicely
正如其他人所说:
[引用]
验证器告诉您隐藏的输入元素不能立即跟随表单标记 - 它需要有某种类型的容器元素。
[/quote]
(来源)
我想字段集可能会有所帮助; 请参阅XHTML DTD:
没有适合您的输入:(
As someone else put it:
[quote]
The validator is telling you that your hidden input element cannot immediately follow the form tag - it needs to have a container element of some kind.
[/quote]
(Source)
I guess a fieldset could help; See The XHTML DTD:
No input for you :(
我遇到了同样的问题,我花了一些时间才弄清楚。 这是 w3c 验证器最近的更改吗? 只是我确信我的一些页面过去曾验证过表单,但现在它们似乎都解决了同一问题的错误。
我以前总是做这样的事情:
并出现验证错误,所以现在我只需在所有标签和输入周围添加 fieldset 或 div 即可对其进行验证,如下所示:
似乎有效,但我确信我过去不必这样做......嗯?
I had the very same problem and it took me some time to figure out. Is this a recent change with the w3c validator? it's just I'm sure some of my pages with forms validated in the past, but now they all seem to through up errors for the same problem.
I used to always do something like:
and get validation errors, so now I just add fieldset or div around all the labels and inputs to get it to validate, like this:
Seems to work, but I'm sure I didn't have to do this in the past... hmmm?
将您的 div 放入表单中。
Put your div inside your form.
您的输入元素应该位于字段集中。 这可以验证并具有使非可视用户代理更容易访问文档的额外好处。
顺便说一句,您的标记有点受到divitis的影响。 您可以直接将类放在表格单元格上,而不是在其中嵌套 div 元素(我不会评论使用表格进行布局)。 另外,您可以直接设置表单元素的样式,而不是将其嵌套在 div 中。
无论如何,这是添加了字段集的示例,因此它可以验证:
Your input elements should be within a fieldset. This validates and has the added benefit of making the document more accessible to non-visual user agents.
As an aside, your markup is suffering from divitis a bit. You could put classes on the table cells directly rather than nesting div elements within them (I'm not going to comment on the use of tables for layout). Also, you could style the form element directly rather than nesting it within a div.
Anyway, here's your example with a fieldset added so it validates: