2

我想使用 VML 在 IE 中绘制形状。我想出了以下代码,但它在 IE8 中没有显示任何内容。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>v\: * { behavior:url(#default#VML); display:inline-block }</style>
<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v" />
</head>

<body>
<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>
<object id="VMLRender" codebase="vgx.dll" classid="CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E">
</object> 

<v:rect style="width: 1in; height: 1in; left: 0.5in; top: 6in; rotation:0deg" fillcolor="#ffff00" strokecolor="#ff0000"/> 
</body>
</html>
4

3 回答 3

2

IE8 中的VML 更改:IE8的 VML 更改

于 2011-06-27T09:47:27.807 回答
2
 <html xmlns:v="urn:schemas-microsoft-com:vml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=5" />    
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <style>v\: * { behavior:url(#default#VML); }</style>
    </head>
    <body>
        <v:rect style="width: 1in; height: 1in; left: 0.5in; top: 6in; rotation:0deg" fillcolor="#ffff00" strokecolor="#ff0000"/> 
    </body>
    </html>
于 2012-04-11T08:49:58.333 回答
1

我强烈建议不要使用 VML。

VML 仅在 IE 中受支持。所有其他浏览器都支持 SVG,甚至在 IE 中,IE9 现在也支持 SVG,并且仅有效地支持 VML 作为遗留功能。

当然,如果您尝试支持 IE 版本 8 及更早版本,这对您没有帮助,因为它们只有 VML 而没有 SVG。但是,有许多 Javascript 库允许您使用 SVG 并将即时转换为 IE 的 VML,这意味着您使用 SVG,您可以编写适用于所有浏览器的代码。

这些库中最好的是Raphael。它是一个真正的跨浏览器矢量图形库,默认为 SVG,但在需要时回退到 VML,并使用一致的工具集覆盖所有浏览器的不一致,对开发人员和用户都完全透明。

另一个要考虑的库是SVG2VML。您也可以通过一些谷歌搜索找到其他一些。

希望有帮助。

于 2011-06-27T10:01:52.023 回答