当getElementById不起作用时,如何查找输入字段的id

How to find id of input field when getElementById does not work?

本文关键字:查找 输入 字段 id 不起作用 getElementById 何查找      更新时间:2023-09-26

我正试图在Firefox中编写一个用户脚本javascript代码,用于填写表单。表单可以在这里找到。要填充的第一个输入似乎具有id="txtFirstName",但当我尝试使用getElementById查找元素时,我的控制台日志返回null

这是我正在使用的代码。

console.log(document.getElementById("txtFirstName"));

我最终想使用一堆语句,比如:

document.getElementById("txtFirstName").value="SeanM";

如何找到输入字段的id,以便为其赋值?

在他们的代码中嵌套得很深的是:

<input name="txtFirstName" id="txtFirstName" maxlength="20" value="" required="required" autofocus="autofocus" type="text">

我没有等到DOM完全加载。谢谢大家的帮助。