Method: 1. Directly embed the js code into the script tag pair with the syntax "<script>js code</script>"; 2. Write the js code into a ".js" file, Use the "" statement to introduce the js file.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
There are two ways to combine (connect) js and HTML
The first one: directly embed the js code into the script tag pair Medium
Grammar
<script type="text/javascript"> js代码; </script>
Second: Use the script tag to introduce an external js file
*** Create a js file , write js code
*** and then use the following statement to introduce
<script type="text/javascript" src="js文件路径"></script>
When using the second method, do not write js code in the script tag, as it will not be executed.
Example:
<html> <head> <title>World</title> <style type="text/css"> </style> </head> <body> <script type="text/javascript"> alert("aaaaaa"); </script> </body> </html>
<html> <head> <title>World</title> <style type="text/css"> </style> </head> <body> <script type="text/javascript" src="1.js"> //alert("bbbbb"); 没有效果 </script> </body> </html>
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to connect html to js. For more information, please follow other related articles on the PHP Chinese website!