如何用 HTML 建立隱藏註釋?


註釋用於隱藏內容。

要在 HTML 中建立隱藏註釋,我們要新增 <! --- 標記,用 -- > 結束它。無論在該標記內輸入什麼內容,都會被隱藏。這些註釋讓我們可以輕鬆理解程式碼。

可以把註釋視為對自己的一則筆記,或者可以幫助其他人理解程式碼,而且它也會隱藏 HTML 程式碼,以便瀏覽器不會在網頁上顯示它。

句法

以下是 HTML 中隱藏註釋的語法。

<!—The text to be commented -->

示例

以下是 HTML 中隱藏註釋的示例程式。

<!DOCTYPE html> <html> <body> <!-- The text here is a commented and it is hidden on the web page --> <p>DLF stands for Delhi Land and Finance</p> </body> </html>

示例

以下是 HTML 中隱藏註釋的另一個示例程式。

<!DOCTYPE html> <html> <body> <!-- <ul> <li> 1 </li> <li> 2 </li> <li> 3 </li> </ul> --> <p>Delhi is the capital of India</p> </body> </html>

我們使用 <p> 標記內的內聯註釋標記來隱藏段落內容。

示例

以下是使用內聯註釋標記在 HTML 中隱藏註釋的示例程式。

<!DOCTYPE html> <html> <body> <!-- The text here is a commente and it is hidden on the web page --> <p>DLF stands for Delhi Land and Finance<!--FinanceDelhi Land and Finance is one of the largest commercial real estate developer in India.--></p> </body> </html>

更新於:11-11-2022

1.4 萬+ 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

入門
廣告
© . All rights reserved.