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

Which tag should the javascript code be placed in?

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

Share

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

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

Javascript should be placed in the script tag. The script tag is used to define scripts, which can either contain script statements or introduce script files through the "src" attribute; syntax "code" or "".

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

The javascript code should be placed in the script tag

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.

Syntax:

Js code

Example 1:

[xss_clean] ("Welcome")

JavaScript programs can be placed not only directly in HTML documents, but also in JavaScript script files. JavaScript script files are text files with a .js extension that can be edited using any text editor.

Example 2:

Create a new text file and save it as test.js. Note that the extension .js indicates that the text file is of type JavaScript.

Open the test.js file and write the following JavaScript code in it.

Alert ("Welcome")

Save the JavaScript file. It is recommended that you put the JavaScript file and the web file in the same directory.

JavaScript files cannot be run independently and need to be imported into a web page and executed through a browser. Use tags to import JavaScript files.

Insert a tag inside the tag of the html document. Define the src property and set the property value to a URL string that points to an external JavaScript file. The code is as follows:

Note: when using the < script > tag to include external JavaScript files, the default file type is Javascript. Therefore, regardless of whether the loaded file extension is .js or not, the browser will follow the JavaScript script to parse.

Save the web page document, preview it in the browser, and display it as shown in the figure.

Note: tags that define src attributes should no longer contain JavaScript code. If the code is embedded, only the external JavaScript file is downloaded and executed, and the embedded code is ignored.

This is the end of the content about "which tag the javascript code should be put in". 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