Home >Web Front-end >JS Tutorial >Why do Form Elements Disappear After Executing Document.write?

Why do Form Elements Disappear After Executing Document.write?

Susan Sarandon
Susan SarandonOriginal
2024-10-24 07:15:02508browse

Why do Form Elements Disappear After Executing Document.write?

Document.write Clears Form Elements

Issue:

Upon executing document.write within the validator() function, the checkbox and button elements disappear from the page.

Explanation:

document.write() writes to the document stream. When the validator() function is called via the button's onClick handler, the document has likely finished loading and the stream is closed.

Calling document.write() on a closed document stream automatically invokes document.open(), which clears the document. Consequently, the form elements are removed from the screen.

The above is the detailed content of Why do Form Elements Disappear After Executing Document.write?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn