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(?);
}
별의 피라미드를 인쇄하고 있는데 새 줄을 인쇄 할 수 없습니다.
\n
개행 문자에는를 사용하십시오 .
document.write("\n");
다음을 둘 이상 가질 수도 있습니다.
document.write("\n\n\n"); // 3 new lines! My oh my!
그러나 이것이 HTML로 렌더링되는 경우 개행에 HTML 태그를 사용하는 것이 좋습니다.
document.write("<br>");
Hello\n\nTest
소스 의 문자열 은 다음과 같습니다.
Hello!
Test
문자열 Hello<br><br>Test
은 HTML 소스에서 다음과 같습니다.
Hello<br><br>Test
HTML은 페이지를 보는 사람을 위해 줄 바꿈으로 렌더링되며 \n
, 소스의 다음 줄로 텍스트를 드롭합니다 (HTML 페이지에있는 경우).
어때 :
document.write ("<br>");
(줄 바꿈 만 공백으로 만 표시되므로 html 페이지에 있다고 가정)
용도 <br>
문서에서 줄 바꿈을 만들 태그를
document.write("<br>");
여기에 샘플 바이올린이 있습니다.
사용 "\n"
:
document.write("\n");
줄 바꿈으로 해석 되려면 큰 따옴표로 묶어야합니다.
아니에요.
document.writeln()
당신이 찾고있는 것 또는 document.write('\n' + 'words')
새로운 라인이 사용될 때 더 세분성을 찾고 있다면
새 줄을 만들려면 기호는 '\ n'입니다.
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('\n');
}
페이지에 출력하는 경우 "<br/>"
대신 사용하고 싶을 것입니다 '/n'
;
HTML 페이지에서 :
document.write("<br>");
그러나 JavaScript 파일에있는 경우 새 줄로 작동합니다.
document.write("\n");
또한, CSS와 요소에 대한 쓰기 white-space: pre
및 사용 \n
개행 문자.
문자열의 "\n"
경우 새 줄을주기 위해 작성 합니다. 예를 들어 console.log("First Name: Rex" + "\n" + "Last Name: Blythe");
Will을 입력합니다.
이름 : Rex
성 : Blythe
\ n-> 줄 바꿈 문자가 새 줄을 삽입하는 데 작동하지 않습니다.
str="Hello!!";
document.write(str);
document.write("\n");
document.write(str);
But if we use below code then it works fine and it gives new line.
document.write(str);
document.write("<br>");
document.write(str);
Note:: I tried in Visual Studio Code.
your solution is
var i;
for(i=10; i>=0; i= i-1){
var s;
for(s=0; s<i; s = s+1){
document.write("*");
}
//printing new line
document.write("<br>");
}
\n dosen't work. Use html tags
document.write("<br>");
document.write("?");
If you are using a JavaScript file (.js) then use document.write("\n");
. If you are in a html file (.html or . htm) then use document.write("<br/>");
.
document.write("\n");
won't work if you're executing it (document.write();
) multiple times.
I'll suggest you should go for:
document.write("<br>");
P.S I know people have stated this answer above but didn't find the difference anywhere so :)
Try to write your code between the HTML pre tag.
You can use below link: 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('<br>');
}
참고URL : https://stackoverflow.com/questions/5758161/how-do-i-create-a-new-line-in-javascript
'Programming' 카테고리의 다른 글
프로그래밍 방식으로 파일 권한을 변경하려면 어떻게합니까? (0) | 2020.08.11 |
---|---|
pdf 문서를 Webview에 어떻게 표시 할 수 있습니까? (0) | 2020.08.11 |
파이프를 사용하여 두 프로그램간에 간단한 문자열을 보내는 방법은 무엇입니까? (0) | 2020.08.11 |
Ruby에서 모듈 변수 만들기 (0) | 2020.08.11 |
부울 배열을 정수 배열로 변환하는 방법 (0) | 2020.08.11 |