How do I create a new line in Javascript?
问题 var i; for(i=10; i>=0; i= i-1){ var s; for(s=0; s<i; s = s+1){ document.write("*"); } //i want this to print a new line /document.write(?); } I am printing a pyramid of stars, I can't get the new line to print. 回答1: Use the \n for a newline character. document.write("\n"); You can also have more than one: document.write("\n\n\n"); // 3 new lines! My oh my! However, if this is rendering to HTML, you will want to use the HTML tag for a newline: document.write("<br>"); The string Hello\n\nTest