gpt4 book ai didi

javascript - 如何在 元素中访问 SVG 文件的内容?

转载 作者:IT王子 更新时间:2023-10-29 03:21:56 26 4
gpt4 key购买 nike

假设您的 HTML 中有这个:

<img src='example.svg' />

您将如何通过 JavaScript 访问 example.svg 的内容(即 <rect>, <circle>, <ellipse> 等)?

最佳答案

无法从 img 获取引用 svg 的 DOM元素。

如果您使用 <object> , <embed><iframe>但是你可以使用 .contentDocument (首选)获取引用的 svg,或 .getSVGDocument这可能与旧的 svg 插件更兼容。

这是一个 example显示如何获取引用的 svg 的 DOM。

关于javascript - 如何在 <img> 元素中访问 SVG 文件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8102528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com