我如何使公司网站fetch显示在我的浏览器上作为一个可点击的链接



我正在获取公司数据,如徽标,公司标题,描述和网站。当网站通过时,它是一个常规的文本字符串。我希望它在浏览器上显示为一个可点击的链接。

function getCompanyProfile(symbol) {
const url = `https://.appspot.com/api/v3/company/profile/${symbol}`;
fetch(url)
.then((response) => response.json())
.then((data) => {
const profile = data.profile;
companyTitle.textContent = profile.companyName;
companyWebsite.textContent = profile.website;
companyDescription.textContent = profile.description;
price.textContent = "Stock Price: $" + profile.price;
let profileChangesPercent = Number(profile.changesPercentage);
if (profileChangesPercent >= 0) {
changesPercentage.classList.add("green");
} else if (profileChangesPercent < 0) {
changesPercentage.classList.add("red");
}
changesPercentage.textContent = profileChangesPercent.toFixed(2) + "%";
// set logo
let img = document.createElement("img");
img.src = profile.image;
companyLogo.appendChild(img);
console.log(data);
})
.catch((err) => {
console.warn("Something went wrong.", err.message);
});
}

您可以将companyWebsite.textContent = profile.website;更改为companyWebsite.innerHTML = "<a href='" + profile.website + "'>Hyperlink Text</a>"

最新更新