首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript函数innerText

Javascript函数innerText
EN

Stack Overflow用户
提问于 2020-06-23 01:04:06
回答 1查看 292关注 0票数 1

我想要得到“innerText”的值,但是当我写到"lid.innerText I get null value“时,有没有其他方法。

代码语言:javascript
复制
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
      }

    }

 });
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-23 01:36:14

您的元素是<text>,这是<svg>中的一个特殊标记,因此innerText不适用。请改用textContent

代码语言:javascript
复制
  if (document.getElementById(lid).textContent === input) 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62519724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档