02JavaScript use

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:

  1. type: required, indicating the content type of the scripting language used by the code, such as: type: "text/JavaScript"

  2. charset: optional, which means the character set specified by the src attribute

  3. defer: Optional, which means that the script can be delayed until the document is completely parsed and displayed before being executed

  4. src: optional, which means that the external file to be executed is included

  5. 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

Guess you like

Origin blog.csdn.net/weixin_42248871/article/details/110095671