Javascript 基礎(chǔ)教程之注釋
注釋的作用是提高代碼的可讀性,幫助自己和別人閱讀和理解你所編寫的JavaScript代碼,注釋的內(nèi)容不會在網(wǎng)頁中顯示。注釋可分為單行注釋與多行注釋兩種。
我們?yōu)榱朔奖汩喿x,注釋內(nèi)容一般放到需要解釋語句的結(jié)尾處或周圍。
單行注釋://?
請看下面的實例:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>javascript</title> </head> <body> <script type="text/javascript"> //document.write("HELLO "); document.write("WORLD "); //輸出world document.write("php中文網(wǎng) "); document.write("php.cn "); document.write("世界你好"); </script> </body> </html>
我們只注釋了一個輸出hello ? 后面我們還有個注釋,寫上這句話的意思當(dāng)我們運行的時候也是不會顯示在頁面上的,但是這樣別人看你的源碼就更容易理解了
多行注釋:/*注釋內(nèi)容*/
下面我們看一個例子,這樣我們就可以吧前面的倆行給注釋掉,從而不會執(zhí)行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>javascript</title> </head> <body> <script type="text/javascript"> /*document.write("HELLO "); document.write("WORLD "); */ document.write("php中文網(wǎng) "); document.write("php.cn "); document.write("世界你好"); </script> </body> </html>
注:如上述案例,當(dāng)我們需要注釋掉前面2句的時候,也是可以使用快捷鍵 ?ctrl+問號鍵即可 ?前提是要先選中我們要注釋的內(nèi)容