代码之家  ›  专栏  ›  技术社区  ›  Lasagna Cat

不必先检查输入字段元素,就不能填充输入字段?

  •  0
  • Lasagna Cat  · 技术社区  · 5 年前

    我试图用

    document.getElementById('u_4SM_4607').value = 'Peet';

    VM183:1 Uncaught TypeError: Cannot set property 'value' of null
        at <anonymous>:1:45
    

    ,它可以工作,并将用“Peet”填充“First Name”字段。

    为什么我会得到错误代码,为什么它只在我首先检查字段时才起作用?

    input “名字”字段的元素:

    <input name="u_4SM_4607" id="u_4SM_4607" type="text" value="" class=" u-full-width" placeholder="Your first name" aria-required="true">
    

    https://formsmarts.com/html-form-example

    0 回复  |  直到 5 年前
        1
  •  0
  •   yochanan sheinberger    5 年前

    它就像另一个网页。所以如果你不参考这个网页,它就不起作用了。