function getAndModifySVG(url) {
return fetch(url)
// Get SVG response as text
.then(response => response.text())
// Parse to a DOM tree using DOMParser
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
// Find path with id="myPath" and return the d attribute
.then(data => data.getElementById("myPath").getAttribute("d"))
}
2条答案
按热度按时间uwopmtnx1#
您应该能够使用Fetch和DOMParser API。
类似于(但不一定完全)以下内容:
pw136qt22#
这是手写的 typescript ,转换成任何东西!