w3c验证器给出'文档类型不允许元素'输入'这里...'错误 [英] w3c validator gives 'document type does not allow element "input" here...' error

查看:298
本文介绍了w3c验证器给出'文档类型不允许元素'输入'这里...'错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用w3c的验证器验证我的页面时出现此错误。



来源:

 < form action =form.php方法= POST > 
< input type =text/>
< / form>

有人可以告诉我为什么我可能得到这个错误吗?提前感谢!

解决方案

这个答案适用于XHTML,而不是HTML5。 b
$ b


form和body元素只接受
块级别的子元素< form action =/>
< input type =submit> < / form>
...将
产生错误:

文档类型不允许元素
输入这里;缺少p,
h1,h2,h3,h4,h5,h6,
div,pre,address ,fieldset,
ins,delstart-tag。
$ b

在(X)HTML的严格变体中,
元素可能只有块元素
作为其子元素,但表单控件
(例如输入元素)是内联
元素。解决方案是选择一个
块元素,并使用适当的
语义可能包含内联
元素;有用的验证器
产生一个列表,可以帮助你减少
的范围。



当涉及到一个表单时,适当的
元素通常是字段设置或
普通div。

Source - Dorward Online

所以做一些类似于

 < form action =form.phpmethod =post> 
< fieldset>
< input type =text/>
< / fieldset>
< / form>

可以解决您的问题。


I got this error when validating my page with w3c's validator.

Source:

<form action="form.php" method="post">
<input type="text"/>
</form>

Can someone show me why I may have gotten this error? Thanks in advance!

解决方案

This answer applies to XHTML, not HTML5.

The form and body element only accept block level children <form action="/"> <input type="submit"> </form> … will produce the error:

document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag.

In Strict variants of (X)HTML, a form element may have only block elements as its children, but form controls (such as input elements) are inline elements. The solution is to pick a block element with appropriate semantics that may contain inline elements; helpfully the validator produces a list that can help you narrow it down.

When it comes to a form, appropriate elements are usually fieldset or a plain div.

Source - Dorward Online

So doing something like

<form action="form.php" method="post">
    <fieldset>
        <input type="text"/>
    </fieldset>
</form>

will solve your problem.

这篇关于w3c验证器给出'文档类型不允许元素'输入'这里...'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆