<script></script> tags
To use JavaScript in HTML, you need to use the <script></script> tag and define the type attribute value as text/javascript, as shown in the previous alert pop-up prompt box example:
The code copy is as follows:
<script type="text/javascript">
alert("I am the prompt text!");
</script>
Usually, separate JavaScript code is meaningless. JavaScript code is generally used in conjunction with HTML code, because JavaScript is originally created to make up for HTML flaws. Here is an example of how JavaScript code and HTML code are used together:
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
alert("I am the prompt text!");
</script>
</head>
<body>
<div>Pictures and text content</div>
</body>
</html>
Usually, JavaScript code (<script></script> tag) is placed within the <head></head> tag. For more details, please refer to "Where is JavaScript code placed in HTML? 》.