JavaScript scripts can be placed anywhere in the HTML document where they are needed. In general, you can place JavaScript script code between
One, placed between
JavaScript script code placed between
1<Html>2<Head>3<Title> Placed in<Head> and</Head> Between tag Pairs</Title>4<!--Write JavaScript code directly-5<ScriptType= "Text/javascript">6//JavaScript code7</Script>8<!--Introducing External Scripts-9<Scripttype= "Text/javascript" Src= "1.js" ></< Span style= "color: #800000;" >script>10 </< Span style= "color: #800000;" >head>11 <body>12 </< Span style= "color: #800000;" >body>13 </< Span style= "color: #800000;" >html>
B. Place between <body> and </body> mark pairs
JavaScript scripts can also be placed between <body> and </body> tag pairs, and can be written as many separate script snippets as needed and combined with HTML code.
1<Html>2<Head>3<Title> Placed in<body> and</Body> Between tag Pairs</Title>4</Head>5<Body>
6 <!--Write JavaScript code directly-
7<ScriptType= "Text/javascript">
8 //javascript code
9 script>
<!-- introduce external script --
11 <script type= "Text/javascript" Src= "1.js" ></< Span style= "color: #800000;" >script> </body> </html>
Note: There can be multiple blocks of code within the
Description: Browsers typically render HTML from top to bottom, and when JavaScript code is encountered, the browser will block (no longer parsing any subsequent code, including HTML and JavaScript). Some browsers do not parse the HTML code behind the JavaScript during blocking, and must wait until the JavaScript code has finished executing before parsing continues. This behavior often occurs when you place JavaScript between
Therefore, we strongly recommend placing JavaScript code at the end of <body>...</body> without special requirements. Such as:
<Body><!--HTML code -<Scripttype= "Text/javascript"></scirpt><Script Type="Text/javascript"src="1.js"></scirpt></body>
Original link: http://www.itxueyuan.org/view/6297.html
Where to embed JavaScript scripts