如何在 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>
廣告