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: