为什么不在p中嵌套验证为XHTML [英] Why doesn't form nested in p validate as XHTML

查看:125
本文介绍了为什么不在p中嵌套验证为XHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-strict.dtd> 
< html xmlns =http://www.w3.org/1999/xhtmlxml:lang =enlang =en>
< head>
< title>网页< / title>
< / head>
< body>
< p>
< form action =something.phpmethod =get>
< input type =submitvalue =Hello/>
< / form>
< / p>
< / body>
< / html>


解决方案

查看您尝试获取的错误消息与 http://validator.w3.org



除了没有指定字符编码(因此它假定为UTF-8)的警告外,主要错误是< p> isn'允许包含非内联内容。您可以完全移除< p> < / p> ,或者在<对于'为什么',这是因为这是它在架构中定义的方式,它定义了什么是和什么是无效的XHTML。如果您查看 XHTML定义的这一部分你会看到< p> 只允许包含文本或'inline'(而不是'block')标签。然而, < form> ; 被视为'块'内容而不是'内联'内容。



换句话说,表单可以包含段落,但是段落不能包含表单。


<!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" xml:lang="en" lang="en">
<head>
  <title>A webpage</title>
</head>
<body>
  <p>
  <form action="something.php" method="get">
    <input type="submit" value="Hello"/>
  </form>
</p>
</body>
</html>

解决方案

Look at the error messages that you get when you try that with http://validator.w3.org

Apart from a warning that you haven't specified a character encoding (and that it's therefore assuming UTF-8), the main error is that a <p> isn't allowed to contain non-inline content. You can either remove the <p> and </p> completely, or, move them inside the <form>.

As for 'why', it's because that's how it's defined in the schema which defines what is and what is not valid XHTML. If you look at this section of the XHTML definition you'll see that <p> is only allowed to contain text or 'inline' (not 'block') tags. However a <form> counts as 'block' content not as 'inline' content.

In other words, a form can contain paragraphs, but a paragraph cannot contain forms.

这篇关于为什么不在p中嵌套验证为XHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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