我想要得到“innerText”的值,但是当我写到"lid.innerText I get null value“时,有没有其他方法。
function zoom() {
var input = document.getElementById("myInput").value; //value from searchbox
// console.log(input);
d3.json("intervals.json", function(alldata) // entering json file to look for oid
{
var i;
for (i = 0; i < alldata.records.length; i++) //for loop for getting the oid alldata.records.length;
{
conceptid = alldata.records[i].oid; //saving all the oid in conceptid
lid = ("l" + conceptid.toString()); //concatenate with "l"
console.log(lid);
if (document.getElementById(lid).innerText === input) // if lid.innertext = input
{
document.getElementById(lid).click(); //then zoom
}
}
});
}发布于 2020-06-23 01:36:14
您的元素是<text>,这是<svg>中的一个特殊标记,因此innerText不适用。请改用textContent:
if (document.getElementById(lid).textContent === input) https://stackoverflow.com/questions/62519724
复制相似问题