Javascript 函数 innerText
Javascript function innerText
我想获取“lid”的 innerText 但是当我写“lid.innerText 我得到空值还有其他方法吗。
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
}
}
});
}
您的元素是 <text>
,它是 <svg>
中的一个特殊标记,因此 innerText
不适用。使用 textContent
代替:
if (document.getElementById(lid).textContent === input)
我想获取“lid”的 innerText 但是当我写“lid.innerText 我得到空值还有其他方法吗。
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
}
}
});
}
您的元素是 <text>
,它是 <svg>
中的一个特殊标记,因此 innerText
不适用。使用 textContent
代替:
if (document.getElementById(lid).textContent === input)