为什么这个 XHTML 表单无法验证?

发布于 2024-07-08 21:14:05 字数 1308 浏览 11 评论 0 原文

任何想法为什么这不会在这里验证:

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>

Any ideas why this won't validate here:

http://validator.w3.org/#validate_by_input

It seems the form input tags are wrong but reading through the XHTML spec they should validate fine. Any ideas?

<!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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

合约呢 2024-07-15 21:14:05

尝试在输入周围放置一个 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.

怀中猫帐中妖 2024-07-15 21:14:05

您需要移动

<div class="Controls">

它,使其位于 标签内部


这很好地验证了

<!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>
                <form id="ControlForm" method="get" action="Edit.php">
                    <div class="Controls">
                        <input type="submit" name="action" id="Edit" value="Edit" />
                        <input type="submit" name="action" id="New" value="New" />
                    </div>
                </form>
            </td>
        </tr>
        </table>
    </div>
</body>
</html>

You need to move

<div class="Controls">

so that it's inside the <form tag


This validates nicely

<!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>
                <form id="ControlForm" method="get" action="Edit.php">
                    <div class="Controls">
                        <input type="submit" name="action" id="Edit" value="Edit" />
                        <input type="submit" name="action" id="New" value="New" />
                    </div>
                </form>
            </td>
        </tr>
        </table>
    </div>
</body>
</html>
雪化雨蝶 2024-07-15 21:14:05

正如其他人所说:

[引用]
验证器告诉您隐藏的输入元素不能立即跟随表单标记 - 它需要有某种类型的容器元素。
[/quote]

(来源)

我想字段集可能会有所帮助; 请参阅XHTML DTD

<!ELEMENT form %form.content;>

<!ENTITY % form.content "(%block; | %misc;)*">

<!ENTITY % misc "noscript | %misc.inline;">
<!ENTITY % misc.inline "ins | del | script">

<!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table">

<!ENTITY % heading "h1|h2|h3|h4|h5|h6">
<!ENTITY % lists "ul | ol | dl">
<!ENTITY % blocktext "pre | hr | blockquote | address">

没有适合您的输入:(

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:

<!ELEMENT form %form.content;>

<!ENTITY % form.content "(%block; | %misc;)*">

<!ENTITY % misc "noscript | %misc.inline;">
<!ENTITY % misc.inline "ins | del | script">

<!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table">

<!ENTITY % heading "h1|h2|h3|h4|h5|h6">
<!ENTITY % lists "ul | ol | dl">
<!ENTITY % blocktext "pre | hr | blockquote | address">

No input for you :(

你如我软肋 2024-07-15 21:14:05

我遇到了同样的问题,我花了一些时间才弄清楚。 这是 w3c 验证器最近的更改吗? 只是我确信我的一些页面过去曾验证过表单,但现在它们似乎都解决了同一问题的错误。

我以前总是做这样的事情:

<div>
<form>
    <label></label>
    <input />
    <label></label>
    <input />
    <label></label>
    <input />
</form>

并出现验证错误,所以现在我只需在所有标签和输入周围添加 fieldset 或 div 即可对其进行验证,如下所示:

<div>
<form>
    <fieldset>or<div>
        <label></label>
        <input />
        <label></label>
        <input />
        <label></label>
        <input />
    </fieldset>or</div>
</form>

似乎有效,但我确信我过去不必这样做......嗯?

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:

<div>
<form>
    <label></label>
    <input />
    <label></label>
    <input />
    <label></label>
    <input />
</form>

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:

<div>
<form>
    <fieldset>or<div>
        <label></label>
        <input />
        <label></label>
        <input />
        <label></label>
        <input />
    </fieldset>or</div>
</form>

Seems to work, but I'm sure I didn't have to do this in the past... hmmm?

暖树树初阳… 2024-07-15 21:14:05
<!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>

                            <form id="ControlForm" method="get" action="Edit.php">
                                <div class="Controls">
                                                <input type="submit" name="action" id="Edit" value="Edit" />
                                                <input type="submit" name="action" id="New" value="New" />
                                </div>
                            </form>

                        </td>
                </tr>
        </table>
    </div>
 </body>
</html>

将您的 div 放入表单中。

<!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>

                            <form id="ControlForm" method="get" action="Edit.php">
                                <div class="Controls">
                                                <input type="submit" name="action" id="Edit" value="Edit" />
                                                <input type="submit" name="action" id="New" value="New" />
                                </div>
                            </form>

                        </td>
                </tr>
        </table>
    </div>
 </body>
</html>

Put your div inside your form.

迷途知返 2024-07-15 21:14:05

您的输入元素应该位于字段集中。 这可以验证并具有使非可视用户代理更容易访问文档的额外好处。

顺便说一句,您的标记有点受到divitis的影响。 您可以直接将类放在表格单元格上,而不是在其中嵌套 div 元素(我不会评论使用表格进行布局)。 另外,您可以直接设置表单元素的样式,而不是将其嵌套在 div 中。

无论如何,这是添加了字段集的示例,因此它可以验证:

<!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">
                <fieldset>
                  <input type="submit" name="action" id="Edit" value="Edit" />
                  <input type="submit" name="action" id="New" value="New" />
                </fieldset>
              </form>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>

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:

<!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">
                <fieldset>
                  <input type="submit" name="action" id="Edit" value="Edit" />
                  <input type="submit" name="action" id="New" value="New" />
                </fieldset>
              </form>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文