當(dāng)前位置:軟件學(xué)堂 > 資訊首頁(yè) > 網(wǎng)絡(luò)編程 > 編程其他 > JavaScript轉(zhuǎn)義字符

JavaScript轉(zhuǎn)義字符

2012/11/27 21:24:05作者:佚名來(lái)源:網(wǎng)絡(luò)

移動(dòng)端

【實(shí)例介紹】

JavaScript轉(zhuǎn)義字符

JavaScript提供了一些特殊字符,允許在字符串中包括一些無(wú)法直接鍵人的字符。每個(gè)字符都以反斜杠開(kāi)始。反斜杠是一個(gè)轉(zhuǎn)義字符,表示JavaScript解釋器下面的字符為特殊字符。

【基本語(yǔ)法】

\b  退格
\f  走紙換行
\n  換行
\r  回車(chē)
\t  橫向跳格(Ctrl-I)
\'  單引號(hào)
\"  雙引號(hào)
\\  反斜杠

【實(shí)例代碼】

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無(wú)標(biāo)題文檔</title> </head> <body> <Script Language = "JAVAScript"> <!--      //用(\")表示(")      document.write("我們的\"愛(ài)人\"");      document.write("<hr>");      //用(\\)表示(\)      document.write("文件在C:\\Windows\\下");      document.write("<hr>");      //用(\n)表示換行      alert("老婆老婆\n我愛(ài)你");      document.write("<hr>");      //用(\n)表示換行      document.write("<pre>老婆老婆\n我愛(ài)你</pre>");      document.write("<hr>"); --> </Script> </body> </html>

【代碼分析】

在代碼中,加粗部分的代碼標(biāo)記表示換行,如圖所示。

轉(zhuǎn)義字符運(yùn)行效果

 【素材及源碼下載】

請(qǐng)點(diǎn)擊:JavaScript轉(zhuǎn)義字符 下載本實(shí)例相關(guān)素材及源碼

 

標(biāo)簽: JavaScript  轉(zhuǎn)義  字符