The HTML <SCRIPT> label is used to insert Javascript into the HTML page.
Instance
-
Generate text
-
How to Write text in pages
-
Generate common text and tags
-
How to use JavaScript to write common text and labels to pages.
How to put Javascript into HTML pages
<script type="text/javascript">document.write("Hello World!");</script></body>
The above code will generate the following output in the HTML page:
Hello World!
Example:
To insert Javascript into an HTML page, you need to use the <SCRIPT> tag (using the type attribute to define the script language at the same time ).
In this way, <SCRIPT type = "text/JavaScript"> and </SCRIPT> can tell the browser where JavaScript starts and ends.
<script type="text/javascript">...</script></body>
Document. WriteA field is a standard JavaScript command used to write output to a page.
After the document. Write command is input to the <SCRIPT type = "text/JavaScript"> and </SCRIPT>, the browser will execute it as a javascript command. In this way, the browser will write "Hello World!" to the page! ".
<script type="text/javascript">document.write("Hello World!");</script></body>
Tiy
Note: if we do not use the <SCRIPT> label, the browser will put document. Write ("Hello world! ") As plain text, that is, the command itself is written to the page.
Tiy
How to deal with old browsers
Browsers that do not support JavaScript will display scripts as page content. To prevent this, we can use the following HTML comment Tag:
<script type="text/javascript"><!--document.write("Hello World!");//--></script></body>
The two front slashes at the end of the comment line are the annotation symbols of JavaScript, which will prevent the Javascript compiler from compiling this line.