Home > Web Front-end > Front-end Q&A > Can js be written in html?

Can js be written in html?

WBOY
Release: 2022-01-18 11:12:37
Original
5723 people have browsed it

You can write js code in html. The function of the script tag is to define the client script. Just set the value of the tag attribute type to "text/javascript", and the syntax is "".

Can js be written in html?

The operating environment of this tutorial: Windows 10 system, HTML5 version, Dell G3 computer.

Can I write js in html

<script> tag is used to define client-side scripts, such as JavaScript. The </p> <p><script> element can either contain script statements or point to an external script file through the "src" attribute. </p> <p>JavaScript is commonly used for image manipulation, form validation, and dynamic content changes. </p> <p>The type attribute specifies the MIME type of the script. </p> <p>The type attribute identifies the content between the <script> and </script> tags.

MIME type includes two parts: media type and subtype. For JavaScript, the MIME type is "text/javascript".

The following two methods, one is external loading, the other is written directly in the html document:

External loading:

<script type="text/javascript" src="js/jquery.min.js"></script>
Copy after login

Written directly in the html document:

<script type="text/javascript">
//写在这里
</script>
Copy after login

Note: If it is written in the document, it can be written in the head tag or placed in any body. It is usually placed in front of the last line of the body because the effect of js is average. They are all executed after the web page is loaded, and being placed at the end does not affect the loading time of the web page

Recommended tutorial: "html video tutorial"

The above is the detailed content of Can js be written in html?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template