|
1. 轉(zhuǎn)義字符的寫法。 在html標(biāo)簽中使用。 可以寫多個(gè),每有一個(gè)則會(huì)渲染出一個(gè)空格,不會(huì)像按多個(gè)空格鍵一樣,最終只顯示一個(gè)。 <div>1 2</div> // 1 2
<div>1 2</div> // 1 2
注意:&和結(jié)尾的;都不能少
2.  ASCII編碼的寫法。 在html標(biāo)簽中使用。 寫一個(gè)和同時(shí)寫多個(gè)一樣,最終只顯示一個(gè),類似于按空格鍵 <div>1 2</div> // 1 2 <div>1    2</div> // 1 2
在js中使用。
可以使用String.fromCharCode(),參數(shù)是#后面的數(shù)字,可以輸出多個(gè)空格
console.log(1+ String.fromCharCode(32) + String.fromCharCode(32) + String.fromCharCode(32) +2) // 1 2
3.\xa0
\xa0屬于latin(ISO/IEC_8859-1,拉丁字母)中的擴(kuò)展字符集字符,代表空白符nbsp(non-breaking space) 在html標(biāo)簽中使用。 和 一樣,可以寫多個(gè),顯示多個(gè) <div>1    2</div> // 1 2
在js中使用。
在js中不需要&#,且可以連續(xù)寫而不用拼接
console.log(1+ '\xa0\xa0\xa0\xa0' +2) //1 2
4.U+0020
屬于Unicode字符 在js中使用。 用法和\xa0一樣
console.log(1+ '\u0020\u0020\u0020\u0020' +2) // 1 2
5.\x20 標(biāo)準(zhǔn)鍵盤碼值表-十六進(jìn)制 在html標(biāo)簽中使用。 只顯示一個(gè)
<div>1    2</div> // 1 2
在js中使用。
console.log(1+ '\x20\x20\x20\x20' +2) // 1 2
6.%20
對(duì)URI 進(jìn)行解碼的樣式,需要用到decodeURIComponent
在js中使用。
console.log(1+ decodeURIComponent('%20')+decodeURIComponent('%20')+decodeURIComponent('%20') +2) // 1 2
7.\t
這種相當(dāng)于按了tab鍵,一個(gè)相當(dāng)于4個(gè)空格
在js中使用.
console.log(1+ '\t\t\t\t' +2) // 1 2
|
|
|