document.body.appendChild(i)

后端 未结 6 1335
傲寒
傲寒 2020-12-08 19:50

I am getting error only in IE7 as document.body is null; when I debug with Microsoft script editor I am getting the error in the following line: i.e.

6条回答
  •  盖世英雄少女心
    2020-12-08 20:18

    You can appendChild to document.body but not if the document hasn't been loaded. So you should put everything in:

    window.onload=function(){
        //your code
    }
    

    This works or you can make appendChild to be dependent on something else like another event for eg.

    https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_body_append

    As a matter of fact you can try changing the innerHTML of the document.body it works...!

提交回复
热议问题