2 methods and precautions for adding script scripts in html_HTML/Xhtml_Web page production
- 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:
However, the 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:
");
}
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