gpt4 book ai didi

javascript - jQuery 获取 SVG 中指定 ID 的所有元素

转载 作者:行者123 更新时间:2023-11-28 13:37:52 24 4
gpt4 key购买 nike

我使用this jQuery plugin将 SVG 图像加载到 div 中。我想从包含 ID 属性的 SVG XML 数据中获取所有元素 ID。例如,在我的 SVG 图像中,我有带有 ID 属性的 circlepolygon 元素,但有一个没有 ID 属性的 rect 元素。我想从 XML 中获取这两个 ID。

我该怎么做?

我已经在svg函数的onLoad方法中尝试过这个。

$("#image svg").each(function() {
$("#list").append("<option>" + this.id + "</option>");
});

#imagesvg 元素的容器,#listselect 标记。

最佳答案

假设 SVG 已正确添加到页面,您可以使用 "has attribute selector"选择具有 ID 的所有元素:

$("#imag > svg [id]").each(function() {
$("#list").append("<option>" + this.id + "</option>");
});

关于javascript - jQuery 获取 SVG 中指定 ID 的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20077681/

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