【问题标题】:How to select vml elements with jquery or pure javascript?如何使用 jquery 或纯 javascript 选择 vml 元素?
【发布时间】:2013-02-16 23:57:27
【问题描述】:

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

非常感谢。

【问题讨论】:

    标签: javascript jquery html dom vml


    【解决方案1】:

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

    使用 jQuery:

    $("v\\:oval")
    

    使用 JavaScript:

    document.getElementsByTagName("v:oval")
    

    请注意,您需要转义 :

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多