<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Let the HTML text box textarea and other formats with JS reserved </title>
<body>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<textarea name= "Textcontent", cols= "rows=", "id=", "textcontent" ></textarea> <br/>
<input type= "button" Name= "Submit" value= "Convert output" onclick= "outhtml ()"/>
<input name= "checkbox" type= "checkbox" id= "checkbox" value= "checkbox" checked= "Checked"/>
<label for= "checkbox" style= "Color: #F00" > Enable conversion output </label>
</form>
<div id= "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>
<script type= "Text/javascript" >
function outhtml () {
var Getvalue=document.getelementbyid ("Textcontent"). Value;
var endvalue= (Getvalue.replace (/< (. +?) >/gi, "<$1>"). Replace (//gi, " "). Replace (/\n/gi, "|");
/* (1) Escape "<", ">" (2) Change half-width space to (3) Keep line break */
if (document.getElementById ("checkbox"). Checked==true) {
document.getElementById ("Out"). Innerhtml=endvalue;
}else{
document.getElementById ("Out"). Innerhtml=getvalue;
}
}
</script>
</body>
Line break for JS text box