2

我想用 jquery 选择一个 VML 元素而不使用 'id' 或 'class' 但我的尝试没有奏效。

<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,一切都像魅力一样运行。

非常感谢。

4

1 回答 1

3

您可以尝试使用完整的标签名称,即v:oval.

使用 jQuery:

$("v\\:oval")

使用 JavaScript:

document.getElementsByTagName("v:oval")

请注意,您需要转义:.

于 2013-02-17T00:02:58.777 回答