使用 JavaScript 更改网页中的文本
Changing Text in WebPage with JavaScript
我在使用 javascript 代码更新 html 元素时遇到问题。我正在尝试更新 google chrome 控制台上的 html 文本输入。对于前。老板。 com 这是来自 cpuboss
的一些 html 代码
<input placeholder="find a cpu" name="query" type="text" id="product-lookup" autocomplete="off" class="">
我几乎尝试了在 Whosebug 上找到的所有代码示例,但无法更新文本元素。
document.getElementsByName('query').value = "test"
我尝试了 .value .innerhtml .attribute 等等,但它们不起作用。有人可以帮助我为什么这些代码不起作用吗?
document.getElementsByName
returns一个NodeList
,基本上就是一个数组。你会想要第一个,像这样:
document.getElementsByName('query')[0].value = "test";
我在使用 javascript 代码更新 html 元素时遇到问题。我正在尝试更新 google chrome 控制台上的 html 文本输入。对于前。老板。 com 这是来自 cpuboss
的一些 html 代码<input placeholder="find a cpu" name="query" type="text" id="product-lookup" autocomplete="off" class="">
我几乎尝试了在 Whosebug 上找到的所有代码示例,但无法更新文本元素。
document.getElementsByName('query').value = "test"
我尝试了 .value .innerhtml .attribute 等等,但它们不起作用。有人可以帮助我为什么这些代码不起作用吗?
document.getElementsByName
returns一个NodeList
,基本上就是一个数组。你会想要第一个,像这样:
document.getElementsByName('query')[0].value = "test";