javascript
  • jquery
  • node.js
  • google-chrome
  • svg
  • 2013-07-29 102 views 4 likes 
    4

    我使用jQuery控制铬SVG文件,为什么<image>标签被改变的jQuery <img>标签,在Chrome

    $('svg #lotsofimage').append("<image xlink:href='" + conf[thing].base + "' width= '" + conf[thing].width + "px' height= '" + conf[thing].height + "px' x='" + thing_x + "pt' y='" + thing_y + "pt' ></image>"); 
    

    ,但我打开的开发工具,它显示如下:

    <img xlink:href="xxxx" width="xxxx"> 
    <image></image>was instead of <img /> 
    

    如何处理?

    +0

    好吧,所以我检查了。没有''标签。你要做什么? – Fresheyeball

    +2

    @Fresheyeball:'image'是SVG的一部分。 – icktoofay

    +0

    @icktoofay哦对。感谢您澄清 – Fresheyeball

    回答

    5

    这不是jQuery;这是Chrome的DOM实现。试试这个:

    > document.createElement('image').tagName 
    'IMG' 
    

    在Chrome,Firefox和Opera中,似乎只有Chrome能做到这一点。在我检查过的几个标准中我找不到任何这种行为的参考。如果您希望Chrome创建image标记,则可能需要使用document.createElementNS明确地将其置于正确的名称空间中。我不知道如何让jQuery来做到这一点。

    +0

    只是为了确保我没有失去理智。从什么时候有''标签? – Fresheyeball

    +0

    @Fresheyeball:它是SVG的一部分;它不存在于HTML中。我只是证明,如果你尝试创建一个,甚至不使用jQuery,Chrome会将它变成一个'img'标签。 – icktoofay

    相关问题