02JavaScript use
1. Script tag analysis
<script></script> This group of tags is the main method used to insert JavaScript in HTML pages.
Mainly have the following attributes:
-
type: required, indicating the content type of the scripting language used by the code, such as: type: "text/JavaScript"
-
charset: optional, which means the character set specified by the src attribute
-
defer: Optional, which means that the script can be delayed until the document is completely parsed and displayed before being executed
-
src: optional, which means that the external file to be executed is included
-
async: Optional, specifies that the script is executed asynchronously
2. JavaScript code embedding problem
If you want to pop up a string of </script> tags. Write </script> directly, the browser will misunderstand it as the end of JavaScript code.
Solution: Divide the string into two parts and connect them with the "+" plus sign
<script type="text/javascript"> alert('</scr'+'ipt>') </script>
3. Import .JS files through src
<script src="js/02.js" type="text/javascript" charset="utf-8"></script>
Note: The script element with the src attribute should not contain additional JavaScript code between its tags, because it will be ignored