Line break for JS text box

Source: Internet
Author: User

<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, "&lt;$1&gt;"). Replace (//gi, "&nbsp;"). Replace (/\n/gi, "|");

/* (1) Escape "<", ">" (2) Change half-width space to &nbsp; (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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.