画布验证XHTML [英] Canvas validation XHTML
问题描述
我尝试验证我的hxtml文件,但canvas元素有问题。
I am trying to validate my hxtml file but there is a problem with canvas element.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<canvas id="canvas" width="500" height="250" style="background-color:#303030;" > </canvas>
有没有人知道如何克服它?
Does anyone have any idea how to overcome it?
推荐答案
正如评论中所说,使用doctype的HTML5(<!DOCTYPE html>
As was said in the comments, using the doctype for HTML5 (<!DOCTYPE html>
) is the sane choice.
然而,它可能是因为任何原因而被XHTML 1阻塞。一个这样的原因可能是,因为XHTML 1具有真实的DTD,所以它支持使用诸如& nbsp;
和& thorn的实体引用;
。 (XHTML5没有这样的奢侈!)
However, it might be you're stuck with XHTML 1 for whatever reason. One such reason could be, because XHTML 1 has a real DTD, it supports the use of entity references like
and þ
. (XHTML5 doesn't have such luxury!)
如果是这样,你可能已经注意到浏览器已经支持 canvas
,所以你不需要做任何事情,使其工作。所有你需要做的是满足验证器!
If so, you might have noticed that the browsers already support newer elements like canvas
, so you don't really have to do anything to make it work. All you need to do is satisfy the validator!
这里的技巧。所有你需要做的是将更新的元素添加到doctype声明,如同他们是DTD的一部分。
So here's the trick. All you need to do is add the newer elements to the doctype declaration, as if they were part of the DTD.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
[
<!ELEMENT canvas EMPTY>
<!ATTLIST canvas
id ID #IMPLIED
class CDATA #IMPLIED
style CDATA #IMPLIED
title CDATA #IMPLIED
lang CDATA #IMPLIED
xml:lang CDATA #IMPLIED
dir (ltr|rtl) #IMPLIED
onclick CDATA #IMPLIED
ondblclick CDATA #IMPLIED
onmousedown CDATA #IMPLIED
onmouseup CDATA #IMPLIED
onmouseover CDATA #IMPLIED
onmousemove CDATA #IMPLIED
onmouseout CDATA #IMPLIED
onkeypress CDATA #IMPLIED
onkeydown CDATA #IMPLIED
onkeyup CDATA #IMPLIED
height CDATA #IMPLIED
width CDATA #IMPLIED
>
<!ENTITY % InlSpecial.class
" | audio | canvas | embed | iframe | img | math | object | svg | video">
]
>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>Element test</title>
</head>
<body>
<div>
<canvas id="canvas" width="500" height="250" style="background-color:#303030;"></canvas>
</div>
</body>
</html>
顺便说一下,如果你认为这有点多,记住你只需要这样做以满足验证器,因此您可以从ATTLIST中删除除了实际使用的属性(在您的示例中, id
, width
, height
和 style
)。
By the way, if you think this is a bit much, remember that you only need to do this to satisfy the validator, so you can remove all attributes from the ATTLIST except the ones you're actually using (in your example, id
, width
, height
and style
).
这篇关于画布验证XHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!