简体   繁体   中英

How to replace line break in a textarea preview?

I want to preserve line break (input by Enter key) in the preview of mathjax dynamic , I try to do it by javascript (since I think they don't load jquery) replace function, but failed with the hint that getElementById returns a div tag, not a string.

Any solution? Thanks!

I did the following test on a javascript console:

var text = document.getElementById('MathInput').value;
text = text.replace(/\r?\n/g, '<br />');
document.getElementById('MathPreview').innerHTML = text;`
text.replace(/(\r\n|\r|\n)/g, "<br />");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM