javascript - 使用路径id获取SVG路径d属性

标签 javascript jquery svg

我有单独的包含 SVG 路径 ID 的 json。有没有办法使用路径 id 获取 SVG 路径“d”属性?或者有没有办法只使用路径 Id 来填充 SVG 路径?

最佳答案

您可以通过调用 document.getElementById 来获取路径元素,然后您可以从那里获取/设置属性...

var d = document.getElementById("<path id>").getAttribute("d");

document.getElementById("<path id>").setAttribute("fill", "red"); 

关于javascript - 使用路径id获取SVG路径d属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485221/

相关文章:

javascript - 监听选项卡打开/关闭并处理现有选项卡

javascript - OnChange 事件在下拉/选择输入中触发得太快?

html - 我该怎么做才能单击 html 复选框并更改 html 输入的内容?

javascript - 如何检测文档是否回到焦点?

html 和 svg 尺寸问题

javascript - 使用 javascript 为手机应用更改 CSS 样式

javascript - "' x'的含义不是函数或其返回值不可迭代”错误

javascript - 改变div的宽度而不影响里面的内容

html - 使 html svg 对象也成为可点击的链接(在 iphone 上)

javascript - 如何使用replace函数将mark标签连接到字符串中的单个单词?