为什么我不能设置 HTML 元素的 "value" 属性?

Why can't I set the "value" property of my HTML element?

当我尝试 运行 以下代码时,我不断收到错误消息:

Cannot set property "value" of null at "id"

我尝试将 属性 从 value 更改为 innerHTML,但没有成功。如果你能帮助我,我将不胜感激。谢谢!

<div class="input-field s6 col" style="color: white; background-color:transparent;">
  <input id="avatar_url" id="ipoza" type="text" onfocus="style='background-color:white;'" onblur="style='background-color:transparent'" value="http://i01.c.aliimg.com/img/ibank/2014/101/288/1614882101_2028072840.jpg"> <label for="avatar_url"><p>Poza de Profil</p></label>
</div>

<button onclick="i()"></button>
<script type="text/javascript">
  function i() {
    document.getElementById("ipoza").value = "Link";
  }
</script>

每个元素只能有一个 id。您的 input 有 2 个 id,这是不允许的。只需给它 ipoza 中的单个 id 这样你就可以 select 它与 document.getElementById("ipoza").

<div class="input-field s6 col" style="color: white; background-color:transparent;">
  <input id="ipoza" type="text" onfocus="style='background-color:white;'" onblur="style='background-color:transparent'" value="http://i01.c.aliimg.com/img/ibank/2014/101/288/1614882101_2028072840.jpg"> <label for="ipoza"><p>Poza de Profil</p></label>
</div>

<button onclick="i()"></button>
<script type="text/javascript">
  function i() {
    document.getElementById("ipoza").value = "Link";
  }
</script>