Consider this simplified example:
<script>
document.write("something </script> something");
</script>
The browser's HTML parser would see the </script>
within the JavaScript string and interpret that as the end of the script element.
The HTML parser doesn't know about JavaScript syntax - all it knows is that the <script>
element ends at the next </script>
.
(It also knows that you can't have nested <script>
elements, hence the breaking of the opening <script>
as well as the closing </script>
in your example.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…