Javascript Jquery。在控制台中执行,但与HTML一起加载时不会执行
我正在开发一个chrome扩展,它将从HTML中提取一个标识符到一个var中,该var将用于填充表单字段 我试图用Js来完成这一点。但在控制台中收到以下错误: “未捕获类型错误:无法将属性“值”设置为null”Javascript Jquery。在控制台中执行,但与HTML一起加载时不会执行,javascript,jquery,html,google-chrome-extension,Javascript,Jquery,Html,Google Chrome Extension,我正在开发一个chrome扩展,它将从HTML中提取一个标识符到一个var中,该var将用于填充表单字段 我试图用Js来完成这一点。但在控制台中收到以下错误: “未捕获类型错误:无法将属性“值”设置为null” <input type="text" name="currId" placeholder="Current ID" id="searchInput"> someId = "some-thing-nice <!--somehow, the li
<input type="text" name="currId" placeholder="Current ID" id="searchInput">
someId = "some-thing-nice
<!--somehow, the line below was throwing the error with the /value. reddit,stack overflow, and random googling confirmed that I was calling an ID that did not exist in the html/ But it definetly did exist. -->
document.getElementById("searchInput").value = someId;
var webID = (document.getElementById("searchInput").value = someId;
console.log(someId);
铬延伸
someID扩展
一些文本
基本上意味着运行代码块时元素不存在。如果以后使用javascript插入,则需要运行它。如果这就是您想要做的,那么可以在setInterval()中运行它,并在元素确实存在时终止间隔计时器。或者考虑使用变异观察者,谢谢。我要试一试。