When we check the source code of many websites, we will find a lot of comments, especially the Sina.com comment tag which is used to insert comments in the source document. The comment text is generally used as a reference for programmers, especially for the source code of large-scale websites developed by multiple people. If there are no comments, the code written by Programmer A cannot be recognized by Programmer B. In this way, if Programmer A leaves, the code he wrote will be difficult to maintain. With comments, it will be easier to understand the code.
HTML comments are ignored by the browser, and HTML comments written directly inside the website source code will not be displayed on the front end. As shown in the figure above, the green parts are comments and will not be displayed. Through the green text above, we can know what this code means and where the code starts and ends. The HTML comment format is as follows: Copy code The code is as follows:<!-- This is the annotation text by www.jb51.net --> <!-- This is also a comment text, but it can also be wrapped by www.jb51.net --> Advanced functions of HTML comments As the name suggests, HTML comments are a type of comment that explains the internal structure of a program. In fact, this is only the most basic function, but it is precisely because of these functions that are ignored by front-end browsers that modern web programs have conducted more in-depth exploration of annotations, making annotations more and more useful. Effect on CSS/JS in the page HTML comments are also used for Javascript and CSS codes within a page. Many older browsers or browsers that cannot recognize Javascript and CSS will often display text if the code is written directly, which greatly affects reading. Copy code The code is as follows:<!DOCTYPE html> <html> <head> <style> body{color:#F00} </style> <script type="text/javascript"> alert('Welcome to www.jb51.net'); </script> </head> <body> <p>Jbzj!</p> </body> </html> The above code does not use HTML comments. If it is accessed in some old mobile browsers and versions below IE6, the following text will be displayed: Copy code The code is as follows:body{color:#F00} alert('Welcome to www.jb51.net');</p> <p>Jbzj! Even if these older browsers do not recognize tags such as <style> and <script>, these tags will not be displayed according to the tag non-display principle and will be treated as unrecognizable custom tags. The text inside these tags will be displayed directly. There is no doubt that these CSS and Javascript codes do not want to be displayed, so if you use the following commented code, CSS and Javascript will not be displayed. Copy code The code is as follows:<!DOCTYPE html> <html> <head> <style> <!-- body{color:#F00} --!> </style> <script type="text/javascript"> <!-- alert('Welcome to www.jb51.net'); --!> </script> </head> <body> <p>Jbzj!</p> </body> </html> HTML comments are used in MVC design Many modern open source code projects, especially those in the MVC web design style, insert some comments into the traditional HTML code, and then add content such as advertisements to these comments. |
<<: A brief discussion on how to customize the host file in Docker
>>: A complete explanation of MySQL high availability architecture: MHA architecture
After configuring the tabBar in the WeChat applet...
I have written such an article before, but I used...
Table of contents How to view the source code of ...
Table of contents 1. v-text (v-instruction name =...
Effect If you use it, please optimize the code an...
1. Parent components can use props to pass data t...
Problem Description The MySQL startup error messa...
Python connects to MySQL to modify and query data...
What is MyCAT A completely open source large data...
Table of contents Main topic 1. Install Docker on...
I will explain the installation of MySQL under Wi...
In the previous article, we learned about the pas...
Table of contents 1. When the mouse passes over t...
This article is based on the CentOS 7.3 system en...
What is the main function of Docker? At present, ...