2013-02-16 71 views
2

我想用jquery選擇一個VML元素,而不使用'id'或'class',但我的嘗試不起作用。如何選擇jQuery或純JavaScript的vml元素?

<v:oval id="vmlElement" style='width:100pt;height:75pt' fillcolor="red"> </v:oval> 


$(document).ready(function(){ 
    //don't work 
    var oItem = $("v");//from here I should look for the n-th 'v' element, but for this example it is not necessary 
    $(oItem).attr("fillcolor", "green") 
    //alert($(oItem).attr("fillcolor")); 

    //This worked, but I can't use select to id, or class 
    $('#vmlElement').eq(0).attr("fillcolor", "green"); 
}); 

我知道VML它太舊,而且是更好地使用SVG。但由於我們需要與舊版瀏覽器兼容,因此我們必須使用VML。對於所有人來說Normal - Browser我們使用SVG,一切都像魅力一樣運行。

非常感謝。

回答

3

您可以嘗試使用完整的標籤名稱v:oval

使用jQuery:

$("v\\:oval") 

使用JavaScript:

document.getElementsByTagName("v:oval") 

通知你需要躲避: