HTML注釋規(guī)范寫法應該遵循以下標準:
Comments must start with the four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS ( ” (U+003E) character, nor start with a U+002D HYPHEN-MINUS character (-) followed by a “>” (U+003E) character, nor contain two consecutive U+002D HYPHEN-MINUS characters (–), nor end with a U+002D HYPHEN-MINUS character (-). Finally, the comment must be ended by the three character sequence U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN (–>).
標準寫法:
<!--Comment Text-->
錯誤的寫法:
<!-->The Wrong Comment Text-->
?
<!--->The Wrong Comment Text-->
?
<!--The--Wrong--Comment Text-->
?
<!--The Wrong Comment Text--->
一般用于簡單的描述,如某些狀態(tài)描述、屬性描述等
注釋內(nèi)容前后各一個空格字符,注釋位于要注釋代碼的上面,單獨占一行
推薦:
<!-- Comment Text -->
<div>...</div>
不推薦:
<div>...</div><!-- Comment Text -->
<div><!-- Comment Text -->
...
</div>
一般用于描述模塊的名稱以及模塊開始與結(jié)束的位置
注釋內(nèi)容前后各一個空格字符,<!-- S Comment Text -->
表示模塊開始,<!-- E Comment Text -->
表示模塊結(jié)束,模塊與模塊之間相隔一行
推薦寫法:
<!-- S Comment Text A -->
<div class="mod_a">
...
</div>
<!-- E Comment Text A -->
<!-- S Comment Text B -->
<div class="mod_b">
...
</div>
<!-- E Comment Text B -->
不推薦寫法:
<!-- S Comment Text A -->
<div class="mod_a">
...
</div>
<!-- E Comment Text A -->
<!-- S Comment Text B -->
<div class="mod_b">
...
</div>
<!-- E Comment Text B -->
當模塊注釋內(nèi)再出現(xiàn)模塊注釋的時候,為了突出主要模塊,嵌套模塊不再使用
<!-- S Comment Text -->
<!-- E Comment Text -->
而改用
<!-- /Comment Text -->
注釋寫在模塊結(jié)尾標簽底部,單獨一行。
<!-- S Comment Text A -->
<div class="mod_a">
<div class="mod_b">
...
</div>
<!-- /mod_b -->
<div class="mod_c">
...
</div>
<!-- /mod_c -->
</div>
<!-- E Comment Text A -->
更多建議: