Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Do you want to include the reference javascript file in the script tag?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the "reference javascript file should be included in the script tag" related knowledge, editor through the actual case to show you the process of operation, the method of operation is simple and fast, practical, hope that this "reference javascript file to be included in the script tag" article can help you solve the problem.

The reference javascript file should be included in the script tag. Use the src attribute of the script tag to specify the path to the external JavaScript file, syntax "".

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

Do you want to reference javascript files to include script tags

Referencing JavaScript files

Like CSS files, JavaScript code can be stored in a separate file to enhance the repeatability of JavaScript scripts. The JavaScript file is a text type file that can be opened and edited in any text editor. The JavaScript file has the extension js.

Tags are used to define client script, such as JavaScript.

Elements can either contain script statements or point to external script files through the "src" attribute.

When you import a JavaScript file, you can use the

< script >

Tag implementation, through the src attribute of the tag to specify the URL (uniform resource locator) of the JavaScript file.

Example:

Create a new text file, save it as test.js, and write a common function in the file to return the length of the string

/ / Common function: calculates the actual length of a string function strlen (str) {var len;// declares a temporary variable, stores the actual length of the string var ibank / declares the loop variable len = 0, initializes the temporary variable len to 0for (I = 0; I

< str.length; i++){//循环检测字符串中每个字符if(str.charCodeAt(i) >

/ / if the current character is a double-byte character, + 2len + = 2 * * else / / if the current character is a single-byte character, + 1 lencoded;} return len;// returns the actual length}

Create a new html document and introduce test.js.

Var str = "JavaScript programming language"; [xss_clean] ("" + str + ""); / / output variable value [xss_clean] ("

Actual length = "+ strlen (str) +" bytes

"); / / call the function

The use of external JavaScript files can enhance the program developed by JavaScript modularization and improve the code reuse rate. In web page development, users should form the good habit of code reuse and use external JavaScript files when writing JavaScript code, which can improve the speed and efficiency of project development.

This is the end of the introduction about "should the reference javascript file be included in the script tag?" Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report