自定义元素是否需要关闭标记? [英] Do custom elements require a close tag?

查看:106
本文介绍了自定义元素是否需要关闭标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义的元素(不需要内容)似乎没有结束标记就可以正常工作。我想知道它是否只是浏览器的一个怪癖。

Elements I've defined (that don't require contents) seem to work just fine without a closing tag. I'm wondering if it's just a quirk of the browser though.

判决是什么?理论上可行吗?如果解析器在定义之前看到元素会怎样?

What's the verdict? Is it theoretically possible? What if the parser sees the element before its definition?

谢谢!

推荐答案

是。自定义元素需要结束标记。由于解析器,只允许HTML中的某些标记自动关闭。

Yes. Custom elements require a closing tag. Only certain tags in HTML are allowed to be self-closing due to the parser.


以下是void元素的完整列表HTML:

The following is a complete list of the void elements in HTML:

area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr

area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

和:


非空元素必须有一个结束标记,除非该引用的HTML元素部分中该元素的子部分表明它的结束标记可以省略。

A non-void element must have an end tag, unless the subsection for that element in the HTML elements section of this reference indicates that its end tag can be omitted.

http://www.w3.org/TR/html -markup / syntax.html#syntax-elements

这篇关于自定义元素是否需要关闭标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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