【问题标题】:why a <image> tag was changed <img> tag by jquery,in chrome为什么 <image> 标签被 jquery 更改为 <img> 标签,在 chrome 中
【发布时间】:2013-07-28 17:08:15
【问题描述】:

我在chrome中使用jquery来控制SVG文件,

$('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 />

如何处理?

【问题讨论】:

  • 好的,我检查了。没有&lt;image&gt; 标签。你在忙什么?
  • @Fresheyeball:image 是 SVG 的一部分。
  • @icktoofay 哦,对了。谢谢你的澄清

标签: javascript jquery node.js google-chrome svg


【解决方案1】:

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

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

在 Chrome、Firefox 和 Opera 之外,似乎只有 Chrome 能做到这一点。在我检查的一些标准中,我找不到任何关于这种行为的参考。如果您希望 Chrome 创建 image 标记,您可能需要使用 document.createElementNS 将其显式放入正确的命名空间中。我不知道你如何让 jQuery 做到这一点。

【讨论】:

  • 只是为了确保我没有失去理智。从什么时候开始有&lt;image&gt; 标签?
  • @Fresheyeball:它是 SVG 的一部分;它在 HTML 中不存在。我只是在演示,如果您尝试在不使用 jQuery 的情况下创建一个,Chrome 会将其转换为 img 标记。