document.write löscht die Seite

Warum im Code unten beim Aufruf vondocument.write in der Funktionvalidator() Die Formularelemente (das Kontrollkästchen und die Schaltfläche) werden vom Bildschirm entfernt.

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            function validator() {
                if (document.myForm.thebox.checked)
                    document.write("checkBox is checked");
                else 
                    document.write("checkBox is NOT checked");
            }
        </script>
    </head>
    <body>
        <form name="myForm">
            <input type="checkbox" name ="thebox"/>
            <input type="button" onClick="validator()" name="validation" value="Press me for validation"/>
        </form>
    </body>
</html>

Antworten auf die Frage(6)

Ihre Antwort auf die Frage