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

查看:28
本文介绍了自定义元素是有效的 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.

自定义元素是新类型的 DOM 元素,可以由作者.与 装饰器不同,后者是无状态且短暂的, 风俗元素可以封装状态,提供脚本接口.

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 Developers 的优秀的演练文章中可以了解到自定义元素 v1:

However, from this excellent walk through article on Google Developers about Custom Elements 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.

一些资源

  • Example Web Components are available at https://WebComponents.org
  • 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天全站免登陆