)으로 변환하자. 다음 HTML 파일이 있다고 가정 해 보겠습니다.div의 텍스트에서 n을 <br /> (JS
...
<div class="field">
Lorem ipsum dolor sit amet,\nconsectetuer adipiscing elit. ...
</div>
...
<div class="field">
Phasellus faucibus molestie nisl.\nMorbi leo mi,\nnonummy
eget tristique non,\nrhoncus non leo. ...
</div>
...
다음 코드는 HTML과 같은 새로운 라인 (즉 < BR /> 태그)와 \ n 문자를 대체 할 예정이다. 그러나 결과는 < br /> 시퀀스가 그대로 텍스트에 나타나며 페이지에 붙여 넣기 전에 이스케이프 처리 된 것과 같습니다.
$(".field").each(function()
{
var oldText = $(this).text();
var newText = oldText.replace(/\n/g, "<br />");
$(this).text(newText);
});
라틴어 텍스트를 실제 줄 바꾸기 위해 어떻게 수정합니까? 사용 .html()
대신 .text()
$ (이) .html 중에서 (를 newText); – JonasT
'white-space : pre' – SLaks
@SLaks, 멋진. 이는이 시나리오에서 더 나은 접근 방법입니다. – xandercoded