Home > Web Front-end > HTML Tutorial > 2 methods and precautions for adding script scripts in html_HTML/Xhtml_Web page production

2 methods and precautions for adding script scripts in html_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:39:28
Original
1691 people have browsed it
How to add <script>script in html: <br><br></strong><font color="#ff0000">1. You can directly add javascript code to html </font><strong> <br></strong> <br><div class="msgheader"> <div class="right"><span style="CURSOR: pointer" onclick="copycode(getid('phpcode12'));"><u>Copy code</u></span></div>The code is as follows:</div> <div class="msgborder" id="phpcode12"> <br><script type="text/javascript"> <br>//javascritp code<br></script>

When the interpreter embeds the <script> code, the processing of the html page will also be temporarily stopped. <br><br><font color="#ff0000">2. Add external js files </font><strong> <br></strong><br><div class="msgheader"> <div class="right"> <span style="CURSOR: pointer" onclick="copycode(getid('phpcode13'));"><u>Copy code </u></span> </div>The code is as follows:</div> <div class="msgborder" id="phpcode13"> <br><script type="text/javascript" src="Address of external .js code"></script>

Note:
① In XHTML documents, the tag can be omitted, for example:

Copy code
The code is as follows:

tag cannot be omitted in HTML. This tag does not comply with HTML specifications, so it cannot be correctly parsed by some browsers.

② It is best to place the <script> tag before the </body> tag, so that the browser can load the page faster. <br><br>③When using <script> to embed JavaScript code, do not appear the "</script>" string anywhere in the code. For example, the browser will generate an error when loading the following code:

Copy the code
The code is as follows:

");
}

Because according to the rules for parsing embedded code, when the browser encounters the string "", it will think that it is the closing tag. If you want to add a string to your code, you can write
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template