2017-05-08 24 views
1

我想用console.log()打印一些文本。我有幾行,每個我用過一個console.log()。我想創建2段。我怎麼能這樣做?由於如何在Javascript中的console.log()中插入介紹

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

+0

你想讓它使用的console.log只有兩次做什麼?這是個問題嗎? –

+0

「段落」是什麼意思?你問如何打印一個空行? – SLaks

+0

你打算如何閱讀並採取行動? –

回答

1

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. ");

1

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​

1

\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添加到每一行的beginnnig幫助分開了一點。

1

您可以在您的行之間使用\r\n添加一條新行,以便一個cal l的console.log打印前3行。

//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()有一個額外的)

1

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

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

+0

爲了保持完整性,請注意,它不適用於某些較舊的瀏覽器。 IE11 – yezzz

+1

@yezzz同意。無論如何,控制檯日誌是爲開發人員和老年人瀏覽器的支持不是問題在這裏。 :D –

0

我是一個法語的人,並認爲你希望是這樣的。你只是不知道如何解釋它。

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

+0

它是一個不同的問題。 –

+0

問題是關於console.log()而不是HTML表單。我認爲這與語言無關。順便說一句,你寫完美的英文(y) –

+0

@Ahi安達里亞 - 感謝阿比。我的英語很好,因爲我住在美國。我用法語教JavaScript,並多次回答類似的問題。 –