I. Syntax for HTML annotations
<!--comment Content--
Second, the use of HTML annotations
1, General Comments (enhance the readability of the code)
Convenient for others: easy for other programmers to understand your code
Convenience: Easy to understand and revise your own code later, etc.
Often heard such a sentence,"Good code, comments accounted for One-third", here for the moment not to discuss one-third of the comments are more or less, just make it clear that the comments are very important.
My understanding: 1. Good code, need Notes
2. Is there more to note than the better? No
How much is a comment appropriate? Reading some of the great God's articles, the central idea boils down to this: where annotations are needed, the annotation is most appropriate. Seemingly a nonsense, but the word of the endless truth between heaven and earth ah, this should be slowly digested. Not the great god of us, I think as long as you think it is very important and convenient for yourself and others to find and understand the place to comment on it.
The following two articles, the individual feel that there is a certain revelation, I hope you can more in-depth understanding of the comments
Five reasons to avoid code comments
Five code comments that should be avoided
2. Conditional annotations (with CSS)
In the CSS layout, also often use the IE CSS Hack. The if IE conditional annotation plays a very big role! if IE condition annotation, let different versions of IE browser read the ability to recognize the content to set the corresponding CSS style, thereby solving the CSS hack.
If conditions Different versions of the browser comment list: GT: (greater than) greater than; LT: (less than) smaller than; E (equal) equals;
<!--[if ie]> all IE recognizable <! [endif]-->
<!--[if GT IE 5.0]> IE5.0 and IE5.0 above can be identified <! [endif]-->
<!--[if IE 6]> only IE6 recognizable <! [endif]-->
<!--[if Lt IE 6]> IE6 and IE6 The following versions are recognized <! [endif]-->
<!--[if GTE IE 6]> IE6 and IE6 above are recognized <! [endif]-->
<!--[if IE 7]> only IE7 recognizable <! [endif]-->
<!--[if Lt IE 7]> IE7 and IE7 The following versions are recognized <! [endif]-->
<!--[if GTE IE 7]> IE7 and IE7 above are recognized <! [endif]-->
* You can also use Boolean operators with (&), or (|), non (!) to create more complex expressions.
<!--[if! Ie]> In addition to IE can be recognized <! [endif]-->
<!--[if (GT IE 5) & (LT IE 7)]>ie5 and IE7 The following versions are recognized <! [endif]-->
<!--[if (IE 6) | ( IE 7)]>ie6 or IE7 recognizable <! [endif]-->
3. (with Javasctipt) using comment tags to hide scripts not supported by browsers is also a good habit (so that scripts are not displayed as plain text)
< script type = "Text/javascript" > <!-- function Displaymsg () {alert ( " hello world! )} // --> </ script >
Note: The two slash (//) at the end of the comment line is a JavaScript comment symbol. This avoids JavaScript execution and tagging.
Reiterated:
Avoid HTML Misuse of comment annotations in Web pages
There is no need to use comments as little as possible in the Web page, and comments are loaded with the browser, increasing the size of the characters. General analysis of Web pages we can use the DW software, as far as possible, using less comments, try not to use Chinese in the comments to avoid the Chinese encoding problem caused by garbled web pages.
Where do you use the notes?
1, I think important code. For example, in HTML, you think important code layout, it is necessary to annotate annotations, we can use HTML annotations.
2, show others. For example, you write HTML code, some local code needs to explain, but also to others to read and interpret the analysis, this time it is necessary to use HTML annotations.
HTML tag Series (i)--comment label <!---->