Why is code after [removed]() not executed?

前端 未结 8 399
长情又很酷
长情又很酷 2021-01-21 07:36

I have the follwing JavaScript.


    
        

        
8条回答
  •  爱一瞬间的悲伤
    2021-01-21 08:19

    Because calling document.write implicity calls document.open, which clears the document on which it has been called:

    If a document exists in the target, this method clears it

    After the call to document.write, the element you're trying to get a reference to no longer exists in the DOM, and an error is thrown. If you look in the error console it should be something along the lines of the following:

    TypeError: Cannot read property 'txt1' of undefined

提交回复
热议问题