References to javascript files should be included in script tags. Use the src attribute of the script tag to specify the path to the external JavaScript file, with the syntax "<script type="text/javascript" src="file path"></script>".
How to quickly get started with VUE3.0: Enter
the operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
Like
CSS files, JavaScript code can be stored in a separate file to enhance the reproducibility of JavaScript scripts. A JavaScript file is a text file that can be opened and edited in any text editor. The extension of a JavaScript file is js.
The <script> tag is used to define client-side scripts, such as JavaScript.
The <script> element can either contain script statements or point to an external script file through the "src" attribute.
When introducing a JavaScript file, you can use the <script> tag to specify the URL (Uniform Resource Locator) of the JavaScript file through the src attribute of the tag.
Example:
Create a new text file, save it as test.js, write a public function in the file, the function is to return the length of the string
//Public function: Calculate the actual length of the string function strlen(str){ var len;//Declare a temporary variable to store the actual length of the string var i;//Declare the loop variable len = 0;//Initialize the temporary variable len to 0 for(i = 0; i < str.length; i++){//Loop to detect each character in the string if(str.charCodeAt(i) > 255)//If the current character is a double-byte character, +2 len += 2; else //If the current character is a single-byte character, +1 len++; } return len;//Return the actual length value}
Create a new HTML document and introduce test.js.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <!--Introducing external JavaScript files--> <script type="text/javascript" src="test.js" ></script> </head> <script> var str = "JavaScript programming language"; document.write("<h2>" + str + "</h2>");//The value of the output variable document.write("<p>Actual length=" + strlen(str) + "bytes</p >");//Call function</script> <body> </body> </html>
Using external JavaScript files can enhance JavaScript modular development programs and improve code reuse. In web development, users should develop a good habit of code reuse. When writing JavaScript code, use more external JavaScript files, which can improve the speed and efficiency of project development.
Related recommendations: JavaScript learning tutorial.
The above is the details of whether to include JavaScript files in script tags when quoting them. For more information, please pay attention to other related articles on the PHP Chinese website!