HTML 验证器在表单输入类型上给我错误,上下文中不允许元素
这是我的 HTML 验证器给我一个错误的代码:
<input type="text" id="search" name="keywords" />
<input type="submit" value="Search" name="Submit" />
这是 HTML 验证器中错误的屏幕截图 (全尺寸):
这是我收到的错误消息:
所提到的元素不允许出现在您放置它的上下文中; 其他提到的元素是唯一允许存在并且可以包含提到的元素的元素。 这可能意味着您需要一个包含元素,或者可能您忘记关闭前一个元素。
HTML 文件正文中有两种类型的元素:内联元素和块元素。 出现此消息的一个可能原因是您尝试将块级元素(例如“
”或“
”)放入内联元素(例如“”、“ <跨度>”或“<字体>”)。在下面的示例中, tag 是一个内联标签,只能包含其他内联标签。 但是
标签是块标签。 所以一个
标签不能包含在 中 标签。
这是它来自的 html 块:
<li>
<form method="post" action="http://site.com/" >
<div class='hiddenFields'>
<input type="hidden" name="ACT" value="19" />
<input type="hidden" name="XID" value="90ee0994104d8ba87b6ef9b43e998fc8c89e0d9f" />
<input type="hidden" name="RP" value="search/results" />
<input type="hidden" name="NRP" value="" />
<input type="hidden" name="RES" value="" />
<input type="hidden" name="status" value="" />
<input type="hidden" name="weblog" value="forms|alumni_distinguished|housing_faq|international_faq" />
<input type="hidden" name="search_in" value="everywhere" />
<input type="hidden" name="where" value="all" />
<input type="hidden" name="site_id" value="1" />
</div>
<input type="text" id="search" name="keywords" /> <input type="submit" value="Search" name="Submit" />
</form>
</li>
This is the code I have that HTML Validator is giving me an error on:
<input type="text" id="search" name="keywords" />
<input type="submit" value="Search" name="Submit" />
Here is a screen shot of error in HTML Validator (full size):
This is the error message I am receiving:
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.
There are 2 types of elements in the body of a HTML file, inline and block elements. 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>").
In the following sample, the <font> tag is an inline tag which can only contain other inline tags. But the <p> tag is a block tag. So a <p> tag can not be contained in a <font> tag.
This is the block of html that it is from:
<li>
<form method="post" action="http://site.com/" >
<div class='hiddenFields'>
<input type="hidden" name="ACT" value="19" />
<input type="hidden" name="XID" value="90ee0994104d8ba87b6ef9b43e998fc8c89e0d9f" />
<input type="hidden" name="RP" value="search/results" />
<input type="hidden" name="NRP" value="" />
<input type="hidden" name="RES" value="" />
<input type="hidden" name="status" value="" />
<input type="hidden" name="weblog" value="forms|alumni_distinguished|housing_faq|international_faq" />
<input type="hidden" name="search_in" value="everywhere" />
<input type="hidden" name="where" value="all" />
<input type="hidden" name="site_id" value="1" />
</div>
<input type="text" id="search" name="keywords" /> <input type="submit" value="Search" name="Submit" />
</form>
</li>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在 HTML4 / XHTML1 中,您无法将内联内容直接放入
form
元素中。 另一方面,HTML5 提高了这一要求。因此,如果验证错误困扰您(还有更糟糕的事情......),请在最后两个输入周围添加一个
p
或div
元素s。In HTML4 / XHTML1, you can't put inline content directly into a
form
element. HTML5, on the other hand, lifts that requirement.Thus, if the validation error bothers you (there are worse things...), add a
p
ordiv
element around the last twoinput
s.您还没有提到此验证器针对哪个 HTML 版本进行验证。 假设不是XTHML,则输入标签不被关闭。 使用“/>” 意味着您正在提供结束标签。
欲了解更多信息: 参考
但是,此限制不适用于需要所有标签都被关闭。 (或者也许我应该说所有标签都应该关闭的限制仅适用于 XHTML);-)
You haven't mentioned which HTML verion this validator validates against. Assuming that it is not XTHML, The input tag is not to be closed. The use of the "/>" implies that you are supplying a closing tag.
For more information : Reference
However, this restriction would not hold for XHTML which requires that all tags be closed. (or maybe I should say that the restriction that all tags should be closed applies only in XHTML) ;-)
我认为问题在于输入位于
元素中,默认情况下不是 块级元素。 这通常是导致此类“断章取义”错误的原因。 它根本不会损害您的页面,只是阻止其验证。
I believe the problem is that the inputs are in a
<li>
element, which by default is not a block-level element. This is usually the cause of such 'out-of-context' errors. It won't hurt your page at all, but just keep it from validating.您使用的是 HTML 还是 XHTML
http://www.w3schools.com/tags/tag_input.asp
Are you using HTML or XHTML
http://www.w3schools.com/tags/tag_input.asp
您提供的代码之前是否有未闭合的内联元素? 内联元素列表: http://htmlhelp.com/reference/html40/inline.html(对于 html4)
Is there an unclosed inline element before the code you supplied? List of inline elements: http://htmlhelp.com/reference/html40/inline.html (for html4)
例如。
[代码]
[/code]
将输入标签包装在
标签
and be sure to self close the input tag like above.
内
这应该得到验证。
标记
eg.
[code]
[/code]
wrap the input tag within a
tag
and be sure to self close the input tag like above.
This should validate.
Mark