jsÖÐÔõÑù»»ÐÐ
ʹÓà “\n” תÒå×Ö·ûʵÏÖ»»ÐУ¬¿Éͨ¹ý (1) ÔÚ×Ö·û´®ÖÐʹÓà “\n”£»(2) ʹÓÃÄ£°åÎÄ×Ö (`)£»(3) ʹÓà “multiline” ÊôÐÔ£»»ò (4) ʹÓà ascii »»Ðзû (10)¡£
ÔõÑùÔÚ JavaScript Öл»ÐÐ
ÔÚ JavaScript ÖУ¬»»ÐпÉÒÔʹÓà “\n” תÒå×Ö·ûʵÏÖ¡£
ʹÓà “\n” תÒå×Ö·û
×î¼òÆÓµÄÒªÁìÊÇÔÚ×Ö·û´®ÖÐÖ±½ÓʹÓà “\n” תÒå×Ö·û£º
const str = "µÚ 1 ÐÐ\nµÚ 2 ÐÐ"; console.log(str);
µÇ¼ºó¸´ÖÆ
Õ⽫Êä³öÁ½ÐÐÎı¾£¬¸÷Õ¼Ò»ÐС£
ʹÓà Template Literals
Ò²¿ÉÒÔʹÓÃÄ£°åÎÄ×ÖÀ´ÊµÏÖ»»ÐУ¬Ê¹Ó÷´ÒýºÅ (`) ¶ø²»Êǵ¥ÒýºÅ»òË«ÒýºÅ£º
const str = `µÚ 1 ÐÐ µÚ 2 ÐÐ`; console.log(str);
µÇ¼ºó¸´ÖÆ
ÕâÒ²»áÊä³öÁ½ÐÐÎı¾¡£
ʹÓà multiline ÊôÐÔ
¹ØÓÚ¶àÐÐ×Ö·û´®£¬¿ÉÒÔÔÚ×Ö·û´®Ç°Ãæ¼ÓÉÏ “multiline” ÊôÐÔ£º
const str = ` µÚ 1 ÐÐ µÚ 2 ÐÐ`; console.log(str);
µÇ¼ºó¸´ÖÆ
ÕâÑùÒ²¿ÉÒÔÊä³öÁ½ÐÐÎı¾£¬²¢ÇÒ´úÂëÔ½·¢ÇåÎú¡£
ÆäËûÒªÁì
ÉÐÓÐÆäËûÒªÁì¿ÉÒÔʵÏÖ»»ÐУ¬µ«ËüÃDz»Ì«³£Óãº
ʹÓà ASCII »»Ðзû (10)£º¿ÉÒÔ½« ASCII »»Ðзû (Ê®½øÖÆ 10) ת»»Îª×Ö·û£¬µ«½öÔÚijЩÇéÐÎÖÐÊÜÖ§³Ö¡£
ʹÓà CSS£º¿ÉÒÔʹÓà CSS µÄ “white-space” ÊôÐÔÀ´ÉèÖû»Ðзû£¬µ«ÕâÒ²½öÊÊÓÃÓÚ HTML ÇéÐΡ£
ÒÔÉϾÍÊÇjsÖÐÔõÑù»»ÐеÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡