At work today, we need to use textarea to get users' spaces and carriage returns, save the user format, and display them at the front end. If there is always a problem of spaces and line breaks, we will study them carefully, because ie and Firefox are always incompatible, and no good solution is found on the Internet, the code for line feed in ie and Firefox is different through transcoding, firefox contains n and IE is rn, which can be viewed by hexadecimal ascii. The solution is as follows:
$ ("Result "). innerHTML = content. value. toString (). replace (/(r) * n/g, "<br/> "). replace (/s/g, ""); special record.
Effect demonstration Result output JavaScript Code
<Script type = "text/javascript"> var $ = function (id) {return document. getElementById (id);} stopBubble = function (e) {// if an event object is input, it is a non-IE browser if (e & e. stopPropagation) // supports the W3C stopPropation () method e. stopPropagation (); else // otherwise, we must use IE to cancel the event bubble window. event. cancelBubble = true;} function showMsg () {var elem =$ $ ("result"); var content =$ $ ("content"); // alert (elem. innerHTML) // return; // alert (content. value. toString () // $ ("result "). innerHTML = content. value. toString (). replace (/s/g ,""). replace (/rn/g, "<br/>"); // alert (escape (content. value. toString (); $ ("result "). innerHTML = content. value. toString (). replace (/(r) * n/g, "<br/> "). replace (/s/g, "") ;}</script>