document.getelementbyid在循环中返回null

礼物

下面的代码会产生同样令人讨厌的错误。它将在循环的第一遍中返回button元素,但此后仅返回null。有任何想法吗?

 <script>
    function  Check_Submission()
    {var Entry = [];
        for(var i = 0; i < 14; i++)
        {
            for(var j = 0; j < 10; j++)
            {
                 Entry[i] = document.getElementById('Add');
                document.write(Entry + '<br>');
            }
        }
    }
    </script>

    <button id = 'Add' onclick = "Check_Submission()" >Click me.</button>
epascarello

页面加载后不能使用document.write。当您这样做时,它将擦除页面内容。

  • 第一个循环找到元素
  • 您写到页面上,它将删除按钮
  • 由于已将其删除,因此其他迭代无法找到它。

您需要使用DOM方法添加新内容或使用控制台进行调试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

document.getElementById()返回null

document.getElementById返回null

Javascript Document.getElementById返回null

离子2 document.getElementById返回null

document.getElementById 始终返回 null

所有 document.getElementById('') 返回 null

为什么在for循环中使用document.getElementById('')。innerHTML和document.write()的结果不同?

为什么document.getElementById在这里返回null?

无法使用document.getElementById获取元素,返回null

javascript document.getElementById 循环

for 循环的 document.getElementById 问题

document.getElementByID和for循环

循环功能document.getElementById()

document.getElementById返回空

document.getElementById 返回 HTMLDivElement {}

从document.getElementById()。value获取null

Ajax Uncaught TypeError: document.getElementById(...) is null

如果未定义element,document.getelementbyId将返回null吗?

如果具有给定ID的元素存在,则document.getelementbyid('ID')方法返回null

开玩笑+酶,使用mount(),document.getElementById()在_method调用后出现的组件上返回null

Vuejs + Google Maps> document.getElementById,this.refs为div返回null

document.getElementById(“ elementId”)。innerHTML =()的倍数,导致第二个返回为null

当存在具有该 ID 的元素时,为什么 document.getElementById() 返回 null?

document.querySelector返回null

document.getElementById与jQuery $()

Javascript document.getElementById

document.all与document.getElementById

如何使用for循环和document.getElementById创建事件?

document.getElementById('').value返回未定义