2011-06-27 24 views
2

我想利用VML繪製形狀在IE.I用下面的代碼來了,但它並沒有顯示我在IE8什麼..如何在網頁中使用VML?

<!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> 

回答

1

我會強烈建議不要使用VML。

VML僅在IE中受支持。所有其他瀏覽器都支持SVG,即使在IE中,IE9現在也支持SVG,並且只支持VML作爲傳統功能。

當然,如果您試圖支持IE版本8及更早版本,那並不能幫到您,因爲它們只有VML而不是SVG。但是,有許多Javascript庫允許您使用SVG,並且可以隨時轉換爲VML for IE,這意味着您使用SVG時,可以編寫適用於所有瀏覽器的代碼。

這些庫中最棒的是Raphael。它是一個真正的跨瀏覽器矢量圖形庫,默認爲SVG,但在需要時可以回退到VML,並使用一致的工具集涵蓋所有瀏覽器的不一致性,對開發人員和用戶都是完全透明的。

另一個需要考慮的庫是SVG2VML。還有其他一些你可以用Google搜索一下。

希望有所幫助。

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>