繁体   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