严格的文档类型 - 表单和输入元素 [英] Strict doctype - form and input element

查看:95
本文介绍了严格的文档类型 - 表单和输入元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道严格doctype背后的原因,不允许输入元素是表单元素的直接后代。我觉得很烦人的是,我必须包装一个提交按钮,它是另一个块级元素中的块级元素,比如说一个字段集或一个div。然而,我无法找到任何答案,为什么这实际上是。

解决方案

因此,如果您尝试直接将输入一个没有容器元素的表单,并且在xhtml 1.0 strict下验证,你会得到这样的警告:


文档类型不允许元素
输入在这里;缺少p,
h1,h2,h3,h4,h5,h6,
div,pre,address ,fieldset,
ins,delstart-tag✉
提及的元素不允许
出现在
放置它的上下文中;其他提到的
元素是唯一允许存在的
元素,并且可以包含提到的
元素。这可能意味着
您需要一个包含元素,或者
可能是您忘记了
关闭了前一个元素。



此消息的一个可能原因是
,您试图将
块级元素(例如< p>或
< table>)放入内联元素
(例如< a>,< span>或
< font>)。 b

如果你看一下表单元素的W3C定义( http://www.w3.org/TR/html4/interact/forms.html#h-17.3 )你可以看到元素的内容模型被定义为%块(block)。


<!ELEMENT FORM - - (%block; | SCRIPT)+
- (FORM) - 交互式表单 - >


如果您按照%block链接( http://www.w3.org/TR/html4/sgml/dtd.html#block ),它将引导您定义为这些元素类型的元素。以下是:

 <!ENTITY%block 
P |%heading; |%list; |%预格式化| | DL | DIV | NOSCRIPT |
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS>

所以,你可以看到,W3C并没有将输入或按钮定义为块级别元素。您可以搜索该页面的输入,并发现它是formctrl的内容类型:

 <!ENTITY%formctrl INPUT | SELECT | TEXTAREA | LABEL | BUTTON> 

实际上,输入元素默认显示为比块更多的内联块,因为他们不导致他们之前/之后的换行符。所以,不仅仅是内联元素和块级元素。因此,最终,一个表单需要直接的子元素作为块级元素,并且输入元素不符合条件。我希望能清除所有的东西。


Does anyone know the reasoning behind the strict doctype not allowing input elements to be direct descendents of a form element. I find it annoying that i have to wrap a submit button which is a block level element inside another block level element say a fieldset or a div. However, I cannot find an answer anywhere as to why this actually is.

解决方案

So if you try to put an input directly into a form without a container element, and validate under xhtml 1.0 strict, you get this warning:

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 ✉ The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").

And if you look here at the W3C definition of a form element (http://www.w3.org/TR/html4/interact/forms.html#h-17.3) you can see that that the element's content model is defined as "%block".

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

If you follow the "%block" link (http://www.w3.org/TR/html4/sgml/dtd.html#block) that leads you to the elements that are defined as those types of elements. And those are:

<!ENTITY % block
     "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
      BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">

So, as you can see, the W3C doesn't define an input or a button as a block level element. You can search that page for "input" and find that it's content type of "formctrl":

<!ENTITY % formctrl "INPUT | SELECT | TEXTAREA | LABEL | BUTTON">

And, really, input elements default display as more inline-block than block, considering they don't cause line breaks before/after them. So, there are more than just inline elements and block-level elements.

So, in the end, a form needs it's direct children to be block level elements, and input elements don't qualify. I hope that clears everything up.

这篇关于严格的文档类型 - 表单和输入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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