Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript中创建新行?(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.(我正在打印星空金字塔,无法打印新行。)

  ask by Technupe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the \n for a newline character.(将\n用作换行符。)

document.write(" "); You can also have more than one:(您还可以有多个:) document.write(" "); // 3 new lines! My oh my! However, if this is rendering to HTML, you will want to use the HTML tag for a newline:(但是,如果将其呈现为HTML,则需要将HTML标签用于换行符:) document.write("<br>"); The string Hello\n\nTest in your source will look like this:(源代码中的字符串Hello\n\nTest将如下所示:) Hello! Test The string Hello<br><br>Test will look like this in HTML source:(字符串Hello<br><br>Test在HTML源代码中将如下所示:) Hello<br><br>Test The HTML one will render as line breaks for the person viewing the page, the \n just drops the text to the next line in the source (if it's on an HTML page).(HTML页面将以换行符的形式呈现给查看页面的人, \n会将文本拖放到源代码的下一行(如果它在HTML页面上)。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...