How to display different colors of different texts in textarea

Source: Internet
Author: User

How to display different colors of different texts in textarea? If it is to control the style of textarea, all text is a color;

If you put the text in the tag, it does not work because the tag will not be interpreted and is processed as text.

I found a method on the Internet:

I copied the code to txt and changed it to html format. The test takes effect. The html is as follows:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> ff </title>
<Script Language = "JavaScript">
Function ta ()
{
//----------------------------
Var oFont1 = document. createElement ("FONT ");
Var oText1 = document. createTextNode ('China ');
OFont1.style. color = "black ";
Form1.topic. appendChild (oFont1 );
OFont1.appendChild (oText1 );
//----------------------------
Var oFont2 = document. createElement ("FONT ");
Var oText2 = document. createTextNode ('people ');
OFont2.style. color = "# ff3322 ";
Form1.topic. appendChild (oFont2 );
OFont2.appendChild (oText2 );
//----------------------------
Var oFont3 = document. createElement ("FONT ");
Var oText3 = document. createTextNode ('liberation \ R ');
OFont3.style. color = "#00 eeff ";
Form1.topic. appendChild (oFont3 );
OFont3.appendChild (oText3 );
//----------------------------
Var oFont4 = document. createElement ("FONT ");
Var tex = "Haha soldiers ";
Var oText4 = document. createTextNode (tex );
OFont4.style. color = "#00ee00 ";
Form1.topic. appendChild (oFont4 );
OFont4.appendChild (oText4 );
}
</Script>
</Head>
<Body>
<Form name = "form1" action = "" method = "post">
<Textarea id = "test" name = "topic" rows = "10" cols = "40"> </textarea>
<Input type = "button" value = "Submit" onClick = "ta ()">
</Form>
</Body>
</Html>

Copy the preceding code to a TXT file, and then change the TXT file to an HTML file. For example, change it to a.html, open it in a browser, and click Submit. The running result is as follows:

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.