亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript usage

<script></script> tag

To use JavaScript in HTML, you need to use the <script></script> tag and define The type attribute value is text/javascript, as shown in the previous alert pop-up prompt box example:

<script type="text/javascript">
alert("I am the prompt text ! ");
</script>

Usually JavaScript code alone is meaningless. JavaScript code is usually used in conjunction with HTML code, because JavaScript is inherently It was created to make up for the shortcomings of HTML.

JavaScript code can be directly embedded anywhere on the web page, but usually we put the JavaScript code in the <head>:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
    <script type="text/javascript">
    alert("我是提示文字!");
    </script>
</head>
<body>
    <div>圖片及文字內(nèi)容</div>
</body>
</html>


You can also place a JavaScript function into the <body> part of the HTML page:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
    <script type="text/javascript">
    alert("我是提示文字!");
    </script>
    <div>圖片及文字內(nèi)容</div>
</body>
</html>

You can also put the JavaScript code into a separate .js file, and then introduce this file in HTML through <script src="..."></script>

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
 <script src="/static/js/abc.js"></script>
</head>
<body>
  <div>圖片及文字內(nèi)容</div>
</body>
</html>


JavaScript Functions and Events

Usually, we need to execute code when an event occurs, such as when the user clicks a button.

If we put JavaScript code into a function, we can call the function when the event occurs.

You will learn more about JavaScript functions and events in later chapters.



Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <p>獲取當前時間</p> <script> document.write(Date()); </script> </body> </html>
submitReset Code