Sometimes when we do form submission, we often need to save the HTML tag, but textarea does not save the line-wrapping information, so we need to use JS to save textarea and other HTM tags.
Really let the HTML text box in the form of exchange and other formats remain.
If you need to use, directly copy the following textarea in the format of the line to keep the code is OK, the code is as follows:
<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" /><title>Let the HTML text box textarea and other formats with JS reserved</title></Head><Body><formID= "Form1"name= "Form1"Method= "POST"Action=""><textareaname= "Textcontent"cols= "+"rows= " the"ID= "Textcontent"></textarea><BR/><inputtype= "button"name= "Submit"value= "Transform Output"onclick= "outhtml ()" /><inputname= "checkbox"type= "checkbox"ID= "checkbox"value= "checkbox"checked= "Checked" /><label for= "checkbox"style= "COLOR: #F00">Enable conversion output</label></form><DivID= "Out"style= "border:1px solid #F90; padding:10px; background: #FFF8DC; margin-top:10px">Please enter text test with HTML tag in the text box above! </Div><Scripttype= "Text/javascript">/*********************************************************** author Tang guohui, created:2007-12-9 12:30:15****** ****************************************************/functionouthtml () {varGetValue=document.getElementById ("textcontent"). Value;varEndvalue=( (Getvalue.replace (/< (. +?) >/gi,"<$1>"). Replace (/ /gi, " "). Replace(/\n/gi, "<br/>");
/*(1) Escape "<", ">" (2) Change half-width space to (3) Keep line wrapping*/if(document.getElementById ("checkbox"). Checked==true) {document.getElementById (" out"). InnerHTML=Endvalue;}Else{document.getElementById (" out"). InnerHTML=getValue;}}//End outhtml Function</Script></Body></HTML>
This is just an HTML text box textarea in the format with JS to keep the model, you also need to develop to meet your needs, hope that Cenxi website development to share to your content to help you! Reprint please indicate the source, thank you!
Html,js Simple save TextArea line wrapping format