Home Web Front-end HTML Tutorial HTML标签系列(一)--注释标签 <! >_html/css_WEB-ITnose

HTML标签系列(一)--注释标签 <! >_html/css_WEB-ITnose

Jun 24, 2016 am 11:37 AM

一、HTML注释的语法

 

<!--注释内容-->
Copy after login

二、HTML注释的用处 

  1、普通注释(增强代码的可读性)

  方便别人:方便其它程序员了解你的代码

  方便自己:方便以后对自己代码的理解与修改等等

  常常听说这样一句话,“好的代码,注释占三分之一”这里暂且不去讨论三分之一的注释是多是少,只需明确一点,注释很重要。

  我的理解:1.好的代码,需要注释 

       2.注释是不是越多越好呢?不是的

  注释到底多少才合适呢?读了一些大神的文章,中心思想归结为:在需要注释的地方注释最合适。看似一句废话,却道出了天地间无尽的真理啊,这下要慢慢消化啦。不是大神的我们,我觉得只要在自己认为很重要而且方便以后自己和别人查找和理解的地方注释就可以了。

  下面这两篇文章,个人觉得有一定的启示作用,希望大家可以更深入的了解注释

  避免代码注释的五大理由

  五种应该避免的代码注释

  2、条件注释(与CSS)

  在CSS布局中,还常常用到IE CSS Hack。if IE条件注释起着非常大的作用!if IE条件注解,让不同版本IE浏览器读取所能识别条件内容来设置对应CSS样式,从而解决CSS hack。

  

  If条件不同版本浏览器注释列表:gt:(greater than)大于;lt:(less than)小于;e(equal)等于;
  

  

  

  

  

  

  

  

  *还可以与布尔运算符与(&)、或(|)、非(!)一起使用,创建更复杂的表达式。

  

  

  

  3、(与javasctipt)使用注释标签来隐藏浏览器不支持的脚本也是一个好习惯(这样就不会把脚本显示为纯文本)

<script type="text/javascript"><!--function displayMsg(){alert("Hello World!")}//--></script>
Copy after login

  注释:注释行结尾处的两条斜杠 (//) 是 JavaScript 注释符号。这可以避免 JavaScript 执行 --> 标签。

 

重申:

避免html网页中滥用注释注解
在网页中没有必要时候完全尽量少用注释,注释也会随浏览器载入,增加字符大小。一般分析网页我们可以借助DW软件进行,尽量少使用注释,尽量不要在注释中使用中文以免中文编码问题造成网页乱码。

那在什么地方用注释呢?

1、  自己认为重要代码。比如在html中,自己认为重要的代码布局,有必要批注注释说明的,我们可以使用html注解来。
2、给别人看。比如自己写的html代码,有的地方代码需要说明一下,同时要转给别人看和解读分析的,这个时候就有必要使用html注释。

 

 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

See all articles