html - HTML5 中的 svg 内联和 svg 自定义属性

标签 html svg dtd w3c-validation custom-attribute

<!DOCTYPE html>
<html>
...
<body>
<svg version="1.1" id="svg1" data-kind="myvalue"></svg>
</body>
</html>

当我尝试在 w3 站点上验证上面的代码时,我收到了以下错误。

Error: Attribute data-kind not allowed on element svg at this point. ...svg version="1.1" id="svg1" data-kind="button">

如何在 html5 中为内联 SVG 编写自定义属性以及如何创建自定义命名空间或 dtd。如果您可以展示和示例或教程,我将不胜感激。我将等待您帮助解决这个问题。

最佳答案

在 HTML5 中,svg是来自 SVG namespace 的元素.

所以它不是 HTML 元素。

因此您不能使用仅为 HTML 元素定义的属性,其中包括 custom data-* attributesMicrodata属性等

也是not possible to use data-* attributes inside of SVG文档。

关于html - HTML5 中的 svg 内联和 svg 自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25056952/

相关文章:

xml - dtd和ent文件是什么关系?

php - PHP中生日的月份和日期下拉列表

javascript - JS : Implementing custom 'Are you sure you want to leave this page' modal dialog

javascript - 使用 php 从通过 ajax 发送的 dataURI 生成 png 文件

html - SVG 元素似乎具有任意高度

jquery - 形状移动时如何让线条或路径跟随形状

c# - 带有 DTD 解析错误的 .NET Core Web API XML

xml - 元素的属性必须存在并且是 dtd 文件中定义的列表之一

javascript - 如何通过 Jquery 访问正确的标签

javascript - 没有回调的 jQuery 队列命令