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
WBOYOriginal
2016-05-16 16:39:281686browse
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
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
Previous article:Introduction to 3 ways to introduce CSS in HTML_HTML/Xhtml_Web page productionNext article:Introduction to 3 ways to introduce CSS in HTML_HTML/Xhtml_Web page production

Related articles

See more