已从API收集数据。我需要将标记中的文本转换为URL。知道如何使用JS和/或TS做到这一点吗?
我知道了
我的代码:
function changeToLink(){
let tableCells = Array.from(document.getElementsByTagName('td'));
var i;
var proNo = "PR0";
for (i=0; i<tableCells.length; i++ && isContains == true) {
var proFromArray = tableCells[i].innerHTML;
var isContains = proFromArray.includes(proNo);
if(isContains == true){
var text = document.getElementsByTagName('td')[i];
console.log(text);
}
}
}
答案 0 :(得分:0)
这是一个主意:
if(isContains == true){
var tdElement = document.getElementsByTagName('td')[i];
tdElement.InnerHtml = "<a href='http://your_link'>Your Link</a>"
}
答案 1 :(得分:0)
该功能对我有用。
at HTMLButtonElement.newtexttotype
function newtexttotype () {
fetch('https://developer.nps.gov/api/v1/parks?stateCode=ca&api_key=APIKEYHERE')
.then(response => response.json())
.then(data => {newtexthere = data.data});
console.log(newtexthere[0].description);
}