使用嵌入式svg时,如何避免IE中的HTML1500标签不能自动关闭警告? [英] How to avoid HTML1500 Tag cannot be self-closing warning in IE when using embedded svg?

查看:227
本文介绍了使用嵌入式svg时,如何避免IE中的HTML1500标签不能自动关闭警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我认为是相当标准的嵌入式svg:

Using what I believe to be pretty standard embedded svg:

<!DOCTYPE html>
<html>
<body style="padding:50px">

  <svg width="100" height="100">
    <circle cx="50" cy="50" r="20" />
  </svg>

</body>
</html>

IE(11)给我一个警告:"HTML1500:标记不能自动关闭.请使用显式关闭标记." (DevTools的控制台"选项卡).

IE (11) gives me a warning "HTML1500: Tag cannot be self-closing. Use an explicit closing tag." (DevTools, Console tab).

是的,如果我将<circle..更改为:

It's true that if I change the <circle.. to:

<circle cx="50" cy="50" r="20"></circle>

警告消失了,但这对我来说很奇怪.

the warning goes away, but that looks strange to me..

在IE devtools已经偶然发现真实未封闭的标签错误,所以这将是悲伤看到它呈现未有用从这种噪声..

The IE devtools have occasionally found real unclosed-tag errors, so it would be sad to see it render un-useful from this kind of noise..

有什么方法可以使IE开心而无需在各处添加结束标记?

Is there any way of making IE happy without resorting to adding closing tags everywhere?

更新:请注意,问题是关于外国元素",而不是无效元素"( http://www .w3.org/TR/SVG/struct.html#SVGElement ).

Update: Note that the question is about "Foreign elements", not "Void elements" (http://www.w3.org/html/wg/drafts/html/master/single-page.html#elements-2). <svg> is not self-closing (it's defined as belonging to the Container element category: http://www.w3.org/TR/SVG/struct.html#SVGElement).

<circle..被定义为基本形状元素( http://www.w3.org/TR/SVG/shapes.html#CircleElement ),这意味着它是自动关闭的.在阅读html5规范的8.1.2时:

<circle.. is defined as a Basic shape element (http://www.w3.org/TR/SVG/shapes.html#CircleElement), which means that it is self-closing. In reading 8.1.2 of the html5 spec:

其开始标记被标记为自动关闭的外来元素不能具有 任何内容(因为同样,因为没有结束标签,所以没有内容可以 放在开始标签和结束标签之间).外国元素的 开始标记未标记为自动关闭,可以包含文字,字符 参考,CDATA部分,其他元素和注释,但文本 不得包含字符U + 003C LESS-THAN SIGN(<)或 含糊的&符.

Foreign elements whose start tag is marked as self-closing can't have any contents (since, again, as there's no end tag, no content can be put between the start tag and the end tag). Foreign elements whose start tag is not marked as self-closing can have text, character references, CDATA sections, other elements, and comments, but the text must not contain the character U+003C LESS-THAN SIGN (<) or an ambiguous ampersand.

在我看来,

好像是说<svg>元素(即外来元素)中的标签是自动关闭的,如果svg-spec声明它们是自动闭合的,并且在定义开始标签(8.1.2.1)时, #6表示<tagname ... />中的/在例如<br/>,但不在<circle ../>上:

it seems (to me) like it is saying that tags inside an <svg> element (i.e. foreign elements) are self-closing if the svg-spec says they are, and when defining start tags (8.1.2.1), #6 says that the / in <tagname ... /> is optional on e.g. <br/>, but not on <circle ../>:

然后,如果该元素是void元素之一,或者如果该元素是 外来元素,则可能只有一个U + 002F SOLIDUS字符 (/).此字符对空元素没有影响,但对异物有影响 元素,将开始标记标记为自动关闭.

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

因此,我认为该文档是符合原样的.我不确定使用</circle>结束标记是否符合要求.

So I believe the document is conforming as-is. I'm unsure if the using a closing </circle> tag would be conforming.

推荐答案

查看此问题: (非无效)自闭合标签在HTML5中有效吗?

基本上,HTML5并不会自动关闭标签.相反,它具有空标记,例如<br>.这也解释了为什么使用外部js文件时<script>不能自动关闭; <script>不是void元素.您正在编写的SVG实际上是html,因此它必须遵循HTML5的规则,而不是XML的规则.

Basically, HTML5 doesn't really do self-closing tags. Instead it has void tags, like <br>. This also explains why <script> isn't self closing when you are using an external js file; <script> isn't a void element. The SVG you are writing is actually html, so it has to follow HTML5's rules, not XML's.

我认为您应该只添加一个结束标记,以便可以在控制台中获得更重要的警告/错误的好处.另外,如果您的页面是XHTML,我相信您可以使用自闭环标签.

I think you should just add a closing tag so that you can get the benefits of more important warning/errors in the console. Alternatively if your page was XHTML, I believe you could use a self closing circle tag.

这篇关于使用嵌入式svg时,如何避免IE中的HTML1500标签不能自动关闭警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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