을 조작 할 수 있습니다. 그런 다음 replace
을 전역 플래그가있는 정규식을 사용하여 모든 줄 바꿈을 <br/>
으로 바꿉니다. 여러 텍스트 영역을 지원해야하는 경우
var s = s.replace(/\n/g, "<br//>");
//Replace all newline characters by "<br//>"
var textareaContent = s.match(/<textarea>[\s\S]+?<\/textarea>/i);
//Preparation: Selects a textarea
var newString = textareaContent[0].replace(/<br\/\/>/g, "\n");
//Preparation: replaces all "<br//>" inside the textarea by "\n" (newline feed)
s = s.replace(textareaContent[0], newString);
//Replaces the textarea inside the string by the new textarea (= including "\n")
var desiredResult = s.replace(/<br\/\/>/g, "<br/>");
//Replaces the remaining "<br//>" (the ones outside the textarea) by "<br/>"
, 당신은 정규 표현식 개체의 exec
방법과 연계하여 for
루프를 사용할 수 있습니다.
필수 읽기 : http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 –
HTML을 어떻게 만듭니 까? 어쩌면 그것은 처음부터 부러진 것을 사후 처리하는 것보다 쉽다. – Tomalak
@Gaby 일명 G. Petrioli 내가 본 것은 내 물건이 다르다고 생각했다. – Omu