JavaScript usage
tag
To use JavaScript in HTML, you need to use the tag and define The type attribute value is text/javascript, as shown in the previous alert pop-up prompt box example:
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 :
php中文网(php.cn) 图片及文字内容
You can also place a JavaScript function into the part of the HTML page:
php中文网(php.cn) 图片及文字内容
You can also put the JavaScript code into a separate .js file, and then introduce this file in HTML through
php中文网(php.cn) 图片及文字内容
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.