簡體   English   中英

如何在Javascript的console.log()中插入簡介

[英]How to insert an intro in console.log() in Javascript

我想使用console.log()打印一些文本。 我有幾行,每行我都使用console.log()。 我想創建2個段落。 我該怎么辦? 謝謝

  console.log("1 : Lister les contacts"); //paragraph 1 console.log("2 : Ajouter un contact"); //paragraph 1 console.log("0 : Quitter"); //paragraph 1 console.log("Choisissez une option :")); //paragraph 2 

 console.log("1 : Lister les contacts"); //paragraph 1 console.log("2 : Ajouter un contact"); //paragraph 1 console.log("0 : Quitter"); //paragraph 1 console.log("\\n\\nChoisissez une option :"); //paragraph 2​ 

 console.log("1 : Lister les contacts"); //paragraph 1 console.log("2 : Ajouter un contact"); //paragraph 1 console.log("0 : Quitter"); //paragraph 1 console.log(""); //paragraph 1 console.log("Choisissez une option :"); //paragraph 2 

或者,您可以使用\\n換行並使用兩次\\n\\n換行:

 console.log(" p1 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \\n\\n p2 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "); 

\\n是換行, \\t是制表符(縮進)。 另外,您可以“連接”字符串(基本上將它們添加在一起。

var paragraph1 = "1 : Lister les contacts\n";
paragraph1 = paragraph1 + "2 : Ajouter un contact\n";
paragraph1 = paragraph1 + "0 : Quitter\n");
var paragraph2 = "Choisissez une option :";

console.log(paragraph1 + "\n" + paragraph2);

這將導致您顯示的內容沒有縮進,並且段落之間有一行。 注意:單獨的console.log()調用始終位於不同的行上,因此將它們保存在單獨的控制台日志中,最后不需要\\n

另外,您可以在列表中每行的開頭添加\\t ,以幫助將其分開。

您可以在各行之間使用\\r\\n添加新行,以便一次調用console.log打印console.log行。

 //paragraph 1 console.log("1 : Lister les contacts\\r\\n2 : Ajouter un contact\\r\\n0 : Quitter"); //paragraph 2 console.log("Choisissez une option :"); //paragraph 2 

你也有一個額外的)在最后console.log()

您可以將模板文字用於多行字符串。 模板文字由反引號分隔:

 console.log(`1 : Lister les contacts 2 : Ajouter un contact 0 : Quitter `); //paragraph 1 console.log('Choisissez une option :'); //paragraph 2 

我是說法語的人,認為您想要這樣的東西。 您只是不知道如何解釋它。

 <form role="form" class="form-horizontal"> <fieldset> <div class="form-group"> <label class="label">Choisissez une option :</label> <div class="select"> <select class="myoptions"> <option value="1">1 : Lister les contacts</option> <option value="2">2 : Ajouter un contact</option> <option value="3">0 : Quitter</option> </select> </div> </div> </fieldset> </form> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM