自定义元素是否为有效的HTML5? [英] Are custom elements valid HTML5?

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

问题描述

我一直无法找到自定义标签在HTML5中是否有效的明确答案,如下所示:

I've been unable to find a definitive answer to whether custom tags are valid in HTML5, like this:

<greeting>Hello!</greeting>

我没有在规范中找到任何一种方法:

I've found nothing in the spec one way or the other:

http://dev.w3.org/html5 /spec/single-page.html

自定义标签似乎无法通过W3C验证程序进行验证。

And custom tags don't seem to validate with the W3C validator.

推荐答案

自定义元素规范可在Chrome和Opera中使用,并可在其他浏览器上使用。它提供了一种以正式方式注册自定义元素的方法。

The Custom Elements specification is available in Chrome and Opera, and becoming available in other browsers. It provides a means to register custom elements in a formal manner.


自定义元素是可以由$ b定义的新元素DOM元素$ b作者。与装饰者不同,后者是无国籍和短暂的,custom
元素可以封装状态并提供脚本接口。

Custom elements are new types of DOM elements that can be defined by authors. Unlike decorators, which are stateless and ephemeral, custom elements can encapsulate state and provide script interfaces.

自定义元素是更大的W3规范的一部分,称为< Web Components ,以及模板,HTML导入和Shadow DOM。

Custom elements is a part of a larger W3 specification called Web Components, along with Templates, HTML Imports, and Shadow DOM.


Web组件使Web应用程序作者可以定义具有
级别的视觉丰富性和交互性的小部件,这些小部件不能与CSS
单独使用,今天的脚本
库无法实现组合和重用。

Web Components enable Web application authors to define widgets with a level of visual richness and interactivity not possible with CSS alone, and ease of composition and reuse not possible with script libraries today.

但是,从这个 Google开发者关于自定义元素v1的优秀演练文章


自定义元素的名称必须包含破折号( - )。因此< x-tags> < my-element> < my-awesome-app> 都是有效的名字,而< tabs> < foo_bar> 不是。这个要求是这样的,HTML解析器可以将常规元素与自定义元素区分开来。当新标签添加到HTML时,它还确保了向前兼容性。

The name of a custom element must contain a dash (-). So <x-tags>, <my-element>, and <my-awesome-app> are all valid names, while <tabs> and <foo_bar> are not. This requirement is so the HTML parser can distinguish custom elements from regular elements. It also ensures forward compatibility when new tags are added to HTML.

一些资源

  • A "gallery" of Web Components is being compiled at http://customelements.io/
  • WebComponents.js serves as a polyfill for Web Components until they are supported everywhere. See also the WebComponents.js github page & web browser support table.

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

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